我有以下目的:
const schema = {
student: {id: 'student/student'},
students: {id: 'student/students'},
} as const;
interface Schema {
readonly [key: string]: {id: string};
}
type Mapped<V extends Schema, U extends keyof V> = {
[S in V[U]['id']]: V[U];
}
但是当我使用这种类型时,所有的值都可以在每个键上使用
const a: Mapped<typeof schema, keyof typeof schema> = {
'student/student': {id: 'student/student'},
'student/students': {id: 'student/student'},
}