Is it better to use enum or string literal type in TypeScript?
String literal type:
export type Animal = {
id : number,
name : string,
type : "dog" | "cat"
}
Enum:
export enum Type{
dog = "dog",
cat = "cat"
}
export type Animal = {
id : number,
name : string,
type : Type
}
When should I choose one over the other? Are there any best practices or conventions to follow? If the enum is only used by one class and component, is there a significant difference?