Javascript 这在React代码库中起什么作用?

Javascript 这在React代码库中起什么作用?,javascript,reactjs,Javascript,Reactjs,我在React代码库中看到以下内容: export type TypeOfWork = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; 它在干什么 来源:这是flow或typescript语法 它定义的自定义类型只能是0到10之间的数字 export type TypeOfWork = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10; let x: TypeOfWork = 0; x = 12; // <--

我在React代码库中看到以下内容:

export type TypeOfWork = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
它在干什么


来源:

这是flow或typescript语法

它定义的自定义类型只能是0到10之间的数字

export type TypeOfWork = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
let x: TypeOfWork = 0;

x = 12; // <-- compiler would throw an error here
正如你在照片中看到的那样,哪一个会缩小得更好

export const enum TypeOfWork {
  IndeterminateComponent = 0, // Before we know whether it is functional or class
  FunctionalComponent = 1,
  ClassComponent = 2,
  HostRoot = 3, // Root of a host tree. Could be nested inside another node.
  HostPortal = 4, // A subtree. Could be an entry point to a different renderer.
  HostComponent = 5,
  HostText = 6,
  CoroutineComponent = 7,
  CoroutineHandlerPhase = 8,
  YieldComponent = 9,
  Fragment = 10
};