这似乎是一个简单的问题,但我还没有找到答案,或者更可能我不确定要查找的正确内容。
在我的打字稿代码中,我有一个名为的类型Determiner,类似于以下内容:
type Determiner = 'a' | 'an' | 'the' | '' | 'auto';
在我的代码中,我有一个类型的变量,Determiner我根据另一个类型的变量的值重新分配它string。
let determiner: Determiner = 'auto';
const content: string = getNewValue();
现在,通过使用带有所有有效值的 if 语句,我检查的方式有点低效。
if (
content === "a" ||
content === "an" ||
content === "the" ||
content === "" ||
content === "auto"
) {
determiner = content;
}
虽然这可行,但我想知道是否有更容易执行此检查而无需手动枚举所有可能的值。