如果我创建此Flow类型:
export type List = [
'some' |
'strings' |
'allowed' |
'to' |
'use'
];
Run Code Online (Sandbox Code Playgroud)
我不被允许:
const myList: List = [];
这是错误:
empty array literal:
This type is incompatible with a tuple type that expects a 1st element of non-optional type string enum
我唯一能想到的就是添加typeof undefined可能的值列表.但是必须有一种简单的方法让它变空?
gca*_*nti 10
您可能需要定义一个元素的元组
type Element =
'some' |
'strings' |
'allowed' |
'to' |
'use';
export type List = Element[];
// or export type List = Array<Element>;
const myList: List = []
Run Code Online (Sandbox Code Playgroud)