0
私が一緒に仕事JSONデータモデルは、例えば、分岐ノードと$type
キーの存在に基づいて明確化されている特殊なノード、で構成された入れ子構造である:非交和
{ "a": { "b": { "$type": "special" } } }
私は」この使用してフローをモデル化したいdは、しかし、組合は例えば、個別のタグが同じタイプであることを要求しているように見えるタグ:
// @flow
type Special = { $type: 'special'};
type Branch = { $type: ?null, [key:string]: any };
function isSpecial(param: Special | Branch): ?Special {
if (param.$type === 'special') {
return param;
}
}
は、次のエラーを与える:
$ node_modules/.bin/flow check-contents < example.js
-:2
2: type Special = { $type: 'special'};
^^^^^^^^^ string literal `special`. This type is incompatible with
3: type NotSpecial = { $type: ?null, [key:string]: any };
^^^^ null
-:3
3: type NotSpecial = { $type: ?null, [key:string]: any };
^^^^ null. This type is incompatible with
2: type Special = { $type: 'special'};
^^^^^^^^^ string literal `special`
-:3
3: type NotSpecial = { $type: ?null, [key:string]: any };
^^^^ undefined. This type is incompatible with
2: type Special = { $type: 'special'};
^^^^^^^^^ string literal `special`
Found 3 errors
このようなケースを処理する方法はありますか?