I have an interface that uses an enum value in one of its fields:
export enum AnimalType {
DOG,
CAT,
}
export interface DogAttrs {
bones: boolean,
type: AnimalType.DOG
}
and my goal is a function that creates dogs and adds them to the list of dogs.
function addDog(animalList: DogAttrs[]) {
const animal = {
type: AnimalType.DOG,
bones: true
}
animalList.push(animal);
}
but this function says the object I create is wrong and it does not conform to the DogAttrs interface:
Type 'AnimalType' is not assignable to type '"DOG"'.
why is that? and how to fix this?
live example: