flowtype - 需要帮助理解一些 Flow 类型的语法

标签 flowtype relayjs

我正在将带有库 ( Relay ) 的 Flow 类型生成器移植到一个发出 TypeScript 类型的流类型生成器,但对 this snippet 中的某些 Flow 语法有一些疑问:

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,但很难找到答案。链接到文档和/或实现的相关部分也将不胜感激。

最佳答案

$ref , $refType等是正常的类型名称。
$类型前缀是表示实用程序类型的约定,例如 $Keys ,虽然看起来不像这里遵循约定。
%other只是一个普通的字符串。 Relay 可能在内部将字符串用于某些特殊目的。

关于flowtype - 需要帮助理解一些 Flow 类型的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48007315/

相关文章:

javascript - 获取 React 流错误 : module is not a polymorphic type. 如何扩展类?

reactjs - 如何将 React.Children.map 与 React.cloneElement 和 flow@0.53.0 一起使用

reactjs - RelayContainer : Expected prop `%s` to be supplied to `%s` , 但 ' + ' 得到 `undefined` 。如果这是故意的,则传递显式的 `null`

javascript - 如果不满足条件,如何在不重复的情况下执行内部函数?

javascript - React-router-relay 与 Relay 模式不一致吗?

javascript - yarn 运行 babel src/-- -d lib/babel -- src/-d lib/-d 不存在。库/不存在

javascript - 流量: Simpler way to annotate `type | typeof undefined` ?

javascript - 什么是 "types first"流架构?

immutable.js - 具有 Relay-GraphQL 突变的撤销-重做状态遍历模式

caching - 中继缓存如何工作?