I have the following categories of Pet:
type Pet = 'dog' | 'cat'
Then I have types for allowed DogNames and CatNames respectively:
type DogName = 'Jack' | 'Fenton' type CatName = 'Priscilla' | 'Kittykat'
I want to type the following object so that only cat names are allowed under cat and dog names are only allowed under dog, but I also don't want new pet categories to be invented unless they are in the type:
type Pet = 'dog' | 'cat'
type DogName = 'Jack' | 'Fenton'
type CatName = 'Priscilla' | 'Kittykat'
type Pets = {
["dog" in Pet]: {[key in DogName]: boolean}
["cat" in Pet]: {[key in CatName]: boolean}
}
const pets = {
dog: {
Jack: true
},
cat: {
KittyKat: true
}
}
The above does not work, specifically the part of "dog" in Pet
dogandcatmeant to be required inPets?