My plan is to have:
enum hobbies {
music = 'music',
sports = 'sports'
}
type Hobbies <T extends Array<keyof typeof hobbies>> = {
[key in T]: number
}
type Musician = {
hobbies: Hobbies<["music"]>
}
type Racer = {
hobbies: Hobbies<["racing"]> //errors, fine
}
const musician: Musician = {
hobbies: {
music: 2,
racing: 1 //should error but it doesn't
}
}
The thing is that it actually does throw an error, but it does for key in T as well as it's not valid.
So it doesn't error if I define Musician with hobbies.racing
Any solutions for that?