2016-12-05 7 views
1

フロータイプ:可能な文字列の配列を空にすることはできませんか?私は、このフロータイプを作成した場合

export type List = [ 
    'some' | 
    'strings' | 
    'allowed' | 
    'to' | 
    'use' 
]; 

私が許可されていないです: はempty array literal: This type is incompatible with a tuple type that expects a 1st element of non-optional type string enum

私が思い付くことができる唯一のことは、typeof undefinedを追加することです: const myList: List = [];

これは誤りであります可能な値リストに追加します。しかしそれが空であるようにするsimpeler方法がなければならない? https://flowtype.org/docs/arrays.html#tuples:あなたは一つの要素のタプルを定義し

+1

をしたいことがあります。あなたが書いたのは、それらの文字列の1つを含む単一要素の配列の型です。 gcantiはあなたが望むものを達成する方法を説明しました。 –

答えて

7

、あなたはこれがタプル構文である

type Element = 
    'some' | 
    'strings' | 
    'allowed' | 
    'to' | 
    'use'; 

export type List = Element[]; 
// or export type List = Array<Element>; 

const myList: List = [] 
+0

ofcourse!ありがとう! –

関連する問題