访问嵌套流类型

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 目前不起作用):

https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAodAXAngBwKZgB2eAzhngCZgC8YA3qmAIaECCATu01gFxgAkAJTxMKAeUIwsHLlgA8dEnAC2eDAAsAloQDmfAEQAhADKt9YAD5h9AFQCiAZRv6AvgD4wqF40-Z8RUnIKBwx2bR0aAQAFdjh8dmwbXDw5H34YuLwErCT8OWIySgAaMAByFhluUrcin1KlVQ1w0tQ3AG5PME6AYzhCMjByAA8MPgKgkLDdSNtHZyA

Ale*_* L. 6

我将把它分成几种类型,这样会更容易理解:

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用于提取数组项类型。