需要帮助理解一些 Flow 类型的语法
Need help understanding some Flow type syntax
我正在努力移植库附带的 Flow 类型生成器 (Relay) to one that emits TypeScript types, but have some questions about some Flow syntax that’s not obvious to me in this snippet:
import type { FragmentReference } from 'relay-runtime';
export opaque type TypenameInside$ref: FragmentReference = FragmentReference;
export type TypenameInside = ({|
+__typename: 'User',
+firstName: ?string,
+$refType: TypenameInside$ref,
|} | {|
+__typename: 'Page',
+username: ?string,
+$refType: TypenameInside$ref,
|} | {|
// This will never be '%other', but we need some
// value in case none of the concrete values match.
+__typename: '%other',
+$refType: TypenameInside$ref,
|});
即$ref
、$refType
、%other
是什么?或者它们不是流特定的,而是中继特定的?
我尝试搜索 flowtype 文档和 repo,但很难找到答案。链接到文档 and/or 实现的相关部分也将不胜感激。
$ref
、$refType
等都是正常的类型名称。
类型的 $
前缀是表示实用程序类型的约定,例如 $Keys
,尽管此处看起来并不遵循约定。
%other
只是一个普通的字符串。 Relay 可能在内部将字符串用于某些特殊目的。
我正在努力移植库附带的 Flow 类型生成器 (Relay) to one that emits TypeScript types, but have some questions about some Flow syntax that’s not obvious to me in this snippet:
import type { FragmentReference } from 'relay-runtime';
export opaque type TypenameInside$ref: FragmentReference = FragmentReference;
export type TypenameInside = ({|
+__typename: 'User',
+firstName: ?string,
+$refType: TypenameInside$ref,
|} | {|
+__typename: 'Page',
+username: ?string,
+$refType: TypenameInside$ref,
|} | {|
// This will never be '%other', but we need some
// value in case none of the concrete values match.
+__typename: '%other',
+$refType: TypenameInside$ref,
|});
即$ref
、$refType
、%other
是什么?或者它们不是流特定的,而是中继特定的?
我尝试搜索 flowtype 文档和 repo,但很难找到答案。链接到文档 and/or 实现的相关部分也将不胜感激。
$ref
、$refType
等都是正常的类型名称。
类型的 $
前缀是表示实用程序类型的约定,例如 $Keys
,尽管此处看起来并不遵循约定。
%other
只是一个普通的字符串。 Relay 可能在内部将字符串用于某些特殊目的。