[英]What does this do in the React codebase?
我在React代碼庫中看到以下內容:
export type TypeOfWork = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
到底在做什么
來源: https : //github.com/facebook/react/blob/master/src/shared/ReactTypeOfWork.js
這是流程或打字稿語法。
它定義了一個自定義類型,只能是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
在這種情況下,枚舉可能更好(僅適用於打字稿)
https://www.typescriptlang.org/docs/handbook/enums.html
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
};
如您在編譯視圖中所見,這將被更好地縮小
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.