My pet categories consist of 'dog' and 'cat' as defined in the Pet
type:
type Pet = 'dog' | 'cat'
I also have distinct types for allowed names for dogs and cats:
type DogName = 'Jack' | 'Fenton' type CatName = 'Priscilla' | 'Kittykat'
To ensure that only valid names are assigned to the respective pets, I am trying to create a type for an object where cat names are only allowed under 'cat' and dog names under 'dog'. Additionally, I want to restrict the creation of new pet types that do not match the existing ones:
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
}
}
However, there seems to be an issue with the code snippet specifically at "dog" in Pet
.