diff --git a/types/react-is/index.d.ts b/types/react-is/index.d.ts index 35d4b4db12..962d3e1a13 100644 --- a/types/react-is/index.d.ts +++ b/types/react-is/index.d.ts @@ -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 // Christian Chown +// Sebastian Silbermann // 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; export function isElement(value: any): value is ReactElement; export function isForwardRef(value: any): value is ReactElement; export function isFragment(value: any): value is ReactElement; +export function isLazy(value: any): value is LazyExoticComponent; +export function isMemo(value: any): value is MemoExoticComponent; export function isProfiler(value: any): value is ReactElement; export function isPortal(value: any): value is ReactElement; export function isStrictMode(value: any): value is ReactElement; +export function isSuspense(value: any): value is ReactElement; 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; diff --git a/types/react-is/react-is-tests.tsx b/types/react-is/react-is-tests.tsx index 3b41e9d06f..afbf0aabb6 100644 --- a/types/react-is/react-is-tests.tsx +++ b/types/react-is/react-is-tests.tsx @@ -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) =>
); -ReactIs.isForwardRef(forwardRef); // true +ReactIs.isForwardRef(); // true +ReactIs.typeOf() === 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(); // true +ReactIs.typeOf() === ReactIs.Suspense; // true