javascriptreactjsflowtype

What kind of language extension where variable declarations are annotated with types is used by React 16?


I was inspecting some source code until I notice this weird variable declaration which I don't understand fully.

let eventsEnabled : ?boolean = null;

What this means?

Source code from here: https://github.com/facebook/react/blob/v16.0.0-alpha.3/src/renderers/dom/fiber/ReactDOMFiber.js#L83


Solution

  • React uses Flow, a static type checker

    ?boolean is signifying that eventsEnabled is a maybe type, meaning that it can be a boolean, or undefined/null.