Merge pull request #31968 from eps1lon/feat/react-is/16-7

react-is: Add 16.7 features
This commit is contained in:
Daniel Rosenwasser
2019-01-15 15:15:25 -08:00
committed by GitHub
2 changed files with 37 additions and 5 deletions
+15 -3
View File
@@ -1,13 +1,19 @@
// Type definitions for react-is 16.5
// Type definitions for react-is 16.7
// Project: https://reactjs.org/
// Definitions by: Avi Vahl <https://github.com/AviVahl>
// Christian Chown <https://github.com/christianchown>
// Sebastian Silbermann <https://github.com/eps1lon>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
export as namespace ReactIs;
import { ReactElement, ReactType } from 'react';
import {
LazyExoticComponent,
MemoExoticComponent,
ReactElement,
ReactType
} from "react";
export function typeOf(value: any): symbol | undefined;
export function isValidElementType(value: any): value is ReactType;
@@ -17,16 +23,22 @@ export function isContextProvider(value: any): value is ReactElement<any>;
export function isElement(value: any): value is ReactElement<any>;
export function isForwardRef(value: any): value is ReactElement<any>;
export function isFragment(value: any): value is ReactElement<any>;
export function isLazy(value: any): value is LazyExoticComponent<any>;
export function isMemo(value: any): value is MemoExoticComponent<any>;
export function isProfiler(value: any): value is ReactElement<any>;
export function isPortal(value: any): value is ReactElement<any>;
export function isStrictMode(value: any): value is ReactElement<any>;
export function isSuspense(value: any): value is ReactElement<any>;
export const AsyncMode: symbol;
export const ContextProvider: symbol;
export const ContextConsumer: symbol;
export const ContextProvider: symbol;
export const Element: symbol;
export const ForwardRef: symbol;
export const Fragment: symbol;
export const Lazy: symbol;
export const Memo: symbol;
export const Portal: symbol;
export const Profiler: symbol;
export const StrictMode: symbol;
export const Suspense: symbol;
+22 -2
View File
@@ -22,6 +22,12 @@ const ForwardRefComponent = React.forwardRef((props, ref) =>
React.createElement(ClassComponent, { forwardedRef: ref, ...props })
);
const LazyComponent = React.lazy(() =>
Promise.resolve({ default: ForwardRefComponent })
);
const MemoComponent = React.memo(StatelessComponent);
const Context = React.createContext(false);
ReactIs.isValidElementType('div'); // true
@@ -31,6 +37,8 @@ ReactIs.isValidElementType(ForwardRefComponent); // true
ReactIs.isValidElementType(Context.Provider); // true
ReactIs.isValidElementType(Context.Consumer); // true
ReactIs.isValidElementType(React.createFactory('div')); // true
ReactIs.isValidElementType(LazyComponent);
ReactIs.isValidElementType(MemoComponent);
// Determining an Element's Type
@@ -74,5 +82,17 @@ ReactIs.typeOf(null) === undefined;
ReactIs.typeOf(undefined) === undefined;
// ForwardRef
const forwardRef = React.forwardRef((props, ref) => <div />);
ReactIs.isForwardRef(forwardRef); // true
ReactIs.isForwardRef(<ForwardRefComponent />); // true
ReactIs.typeOf(<ForwardRefComponent />) === ReactIs.ForwardRef; // true
// Lazy
ReactIs.isLazy(LazyComponent); // true
ReactIs.typeOf(LazyComponent) === ReactIs.Lazy; // true
// Memo
ReactIs.isMemo(MemoComponent); // true
ReactIs.typeOf(MemoComponent) === ReactIs.Memo; // true
// Suspense
ReactIs.isForwardRef(<React.Suspense fallback={StatelessComponent} />); // true
ReactIs.typeOf(<React.Suspense fallback={StatelessComponent} />) === ReactIs.Suspense; // true