如何在TypeScript中创建预定义的可接受数组值?

如何在TypeScript中创建预定义的可接受数组值?,typescript,interface,type-definition,Typescript,Interface,Type Definition,我在TypeScript中有此对象: validationRules:ValidationRuleInterface={ id:['integer','必需'], 姓名:['string','required','people\u name'], 城市:['string','nullable'], }; 我想在数组中定义某种程度上可以接受的值。大概是这样的: 类型规则=字符串; 接口验证规则接口{ [键:字符串]:规则[] } 有没有办法在TypeScript中定义数组的可能值?您就快到了。

我在TypeScript中有此对象:

validationRules:ValidationRuleInterface={
id:['integer','必需'],
姓名:['string','required','people\u name'],
城市:['string','nullable'],
};
我想在数组中定义某种程度上可以接受的值。大概是这样的:

类型规则=字符串;
接口验证规则接口{
[键:字符串]:规则[]
}

有没有办法在TypeScript中定义数组的可能值?

您就快到了。简单地说,将类型定义更改为

type Rule = 'required' | 'nullable' | 'string' | 'integer' | 'people_name' | null;