enum AllowedFruits {
Apple = 'APPLE',
Banana = 'BANANA',
Pear = 'PEAR'
}
const allowedFruits: AllowedFruits[] = [
AllowedFruits.Apple, AllowedFruits.Banana, AllowedFruits.Pear
]
Run Code Online (Sandbox Code Playgroud)
我想要实现的是将数组限制为具有特定枚举的每个字段。我期望allowedFruits通过添加或删除 的字段来显示类型错误AllowedFruits。
有什么办法可以实现吗?
如果有任何文章或文档可供我参考,请告诉我。