这个“|”是什么意思React 文档中的符号代表什么?
What does this "|" symbol stand for in the React Documentation?
我试图理解 React 源代码,代码库中的许多文件将我引向 shared/ReactTypes.js 文件。
在此文件中,有一个符号“|”
根据我自己的研究,我发现这是按位或 (|) 运算符,解释该运算符的 MDN 文档指出:
returns a 1 in each bit position for which the corresponding bits of either or both operands is 1.
这对我来说没有任何意义,所以我继续在网络上进行一些研究,包括 Google 和 Whosebug,但我在此处的 React 源代码中找不到与其功能相关的任何内容。
export type ReactNode =
| React$Element<any>
| ReactPortal
| ReactText
| ReactFragment
| ReactProvider<any>
| ReactConsumer<any>;
谁能给我解释一下,或者至少给我一些资源来帮助我了解这个 React 源代码中发生的事情。
此外,如果您知道重现此代码的任何方法,请告诉我。
提前致谢!!
That file 是一个 Flow 类型文件,而不是 vanilla JavaScript,所以 MDN 文档在这个意义上不成立。 (事实上 ,它无论如何都不能被解析为常规JavaScript;export type
不是JavaScript中的东西。)
Flow denotes an union type 中的 |
运算符。
(TypeScript typing file for React 有一个等效的模式,即使不完全相同。)
我试图理解 React 源代码,代码库中的许多文件将我引向 shared/ReactTypes.js 文件。
在此文件中,有一个符号“|”
根据我自己的研究,我发现这是按位或 (|) 运算符,解释该运算符的 MDN 文档指出:
returns a 1 in each bit position for which the corresponding bits of either or both operands is 1.
这对我来说没有任何意义,所以我继续在网络上进行一些研究,包括 Google 和 Whosebug,但我在此处的 React 源代码中找不到与其功能相关的任何内容。
export type ReactNode =
| React$Element<any>
| ReactPortal
| ReactText
| ReactFragment
| ReactProvider<any>
| ReactConsumer<any>;
谁能给我解释一下,或者至少给我一些资源来帮助我了解这个 React 源代码中发生的事情。
此外,如果您知道重现此代码的任何方法,请告诉我。
提前致谢!!
That file 是一个 Flow 类型文件,而不是 vanilla JavaScript,所以 MDN 文档在这个意义上不成立。 (事实上 ,它无论如何都不能被解析为常规JavaScript;export type
不是JavaScript中的东西。)
Flow denotes an union type 中的 |
运算符。
(TypeScript typing file for React 有一个等效的模式,即使不完全相同。)