我想知道如何使用a regular JavaScript array作为输入脚本界面的可能字符串列表,因此它的行为将如下所示:
interface MyInterface {
name: "x"|"y"|"z"
}
但我想不出如何正确地映射names
的值:
const names = [`x`, `y`, `z`] as const;
interface MyInteface {
name: (typeof names)[string] // ERROR: Type 'readonly ["x", "y", "z"]' has no matching index signature for type 'string'.
}
const myTest: MyInteface = {
name: `x`
}
我认为这是可能的.有谁有主意吗?
Thanks!个