export = React;
export as namespace React;
declare namespace React {
//
// React Elements
// ----------------------------------------------------------------------
type ElementType<P = any> =
{
[K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K] ? K : never
}[keyof JSX.IntrinsicElements] |
ComponentType<P>;
...
// DOM Elements
function createFactory<T extends HTMLElement>(
type: keyof ReactHTML): HTMLFactory<T>;
...
}
So what does export = React
do?
// Usage
import React from "react"
type Example = React.ReactNode;
// or
import {ReactNode} from "react"
type Example = ReactNode;
Basicly it allows us to export the entrie React namespace
, by using as import React from "react"
, or we can just destruct individual element from namespace import {ReactNode} from "react"
what does export as namespace React;
do?
So in any ts file, you can use React
without import:
type Example = React.ReactNode
If we comment out export as namespace React;
then React
namespace is not availbe;
- React Typescript namespacereact typescript namespace additional typescript attribute namespace 语法typescript namespace class typescript workspace monorepo react typescript component strongly react typescript component generics react react typescript inference fixing typescript strongly render react react typescript examples useful react typescript component strongly