Den*_*sKo 2 javascript flowtype
我得到了一个“大”类型(在这种情况下由中继生成),并且有很多嵌套。现在我需要访问嵌套类型。
示例:我将如何访问此处的“某物”?
/* @flow */
type nested = {
anArray: $ReadOnlyArray<{something: "BLA" | "TEST"}>
}
type nestedString = $PropertyType<
$PropertyType<nested, 'anArray'>,
'something'
>;
const text: nestedString = "TEST"
Run Code Online (Sandbox Code Playgroud)
链接到 Flow REPL(需要切换到 0.64,因为 0.65 目前不起作用):
我将把它分成几种类型,这样会更容易理解:
type nested = {
anArray: $ReadOnlyArray<{something: "BLA" | "TEST"}>
}
type ArrayType = $PropertyType<nested, 'anArray'>;
type ExtractArrayItem = <T>($ReadOnlyArray<T>) => T;
type ArrayItemType = $Call<ExtractArrayItem, ArrayType>;
type nestedString = $PropertyType<ArrayItemType, 'something'>;
const text: nestedString = "TEST";
Run Code Online (Sandbox Code Playgroud)
$Call用于提取数组项类型。
| 归档时间: |
|
| 查看次数: |
885 次 |
| 最近记录: |