From dae946c356bc3606ae3503c62e3d7dd823b00590 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 8 Jan 2019 13:38:11 +0100 Subject: [PATCH 1/5] react-is: sort exports --- types/react-is/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-is/index.d.ts b/types/react-is/index.d.ts index 35d4b4db12..59de5135f0 100644 --- a/types/react-is/index.d.ts +++ b/types/react-is/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-is 16.5 +// Type definitions for react-is 16.7 // Project: https://reactjs.org/ // Definitions by: Avi Vahl // Christian Chown @@ -22,8 +22,8 @@ export function isPortal(value: any): value is ReactElement; export function isStrictMode(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; From 8347dc7f1586ca6b2c139a71160019512045be28 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 8 Jan 2019 14:00:46 +0100 Subject: [PATCH 2/5] react-is: fix forward ref test --- types/react-is/react-is-tests.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-is/react-is-tests.tsx b/types/react-is/react-is-tests.tsx index 3b41e9d06f..3c8031e759 100644 --- a/types/react-is/react-is-tests.tsx +++ b/types/react-is/react-is-tests.tsx @@ -74,5 +74,5 @@ 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 From b4994d69dea56edd8827f25decee5134cc531b9a Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 8 Jan 2019 14:11:56 +0100 Subject: [PATCH 3/5] react-is: Add lazy, memo and suspsense types --- types/react-is/index.d.ts | 7 +++++++ types/react-is/react-is-tests.tsx | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/types/react-is/index.d.ts b/types/react-is/index.d.ts index 59de5135f0..b7cce65e18 100644 --- a/types/react-is/index.d.ts +++ b/types/react-is/index.d.ts @@ -2,6 +2,7 @@ // Project: https://reactjs.org/ // Definitions by: Avi Vahl // Christian Chown +// Sebastian Silbermann // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -17,9 +18,12 @@ 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 ReactElement; +export function isMemo(value: any): value is ReactElement; 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 ContextConsumer: symbol; @@ -27,6 +31,9 @@ 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 3c8031e759..f11ded70a6 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 @@ -76,3 +84,15 @@ ReactIs.typeOf(undefined) === undefined; // ForwardRef ReactIs.isForwardRef(); // true ReactIs.typeOf() === ReactIs.ForwardRef; // true + +// Lazy +ReactIs.isLazy(); // true +ReactIs.typeOf() === ReactIs.Lazy; // true + +// Memo +ReactIs.isMemo(); // true +ReactIs.typeOf() === ReactIs.Memo; // true + +// Suspense +ReactIs.isForwardRef(); // true +ReactIs.typeOf() === ReactIs.Suspense; // true From a762d4c1816f2ec6ba36273033a4eed00ff6860f Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 8 Jan 2019 15:14:21 +0100 Subject: [PATCH 4/5] react-is: fix lazy and memo tests --- types/react-is/react-is-tests.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/react-is/react-is-tests.tsx b/types/react-is/react-is-tests.tsx index f11ded70a6..afbf0aabb6 100644 --- a/types/react-is/react-is-tests.tsx +++ b/types/react-is/react-is-tests.tsx @@ -86,12 +86,12 @@ ReactIs.isForwardRef(); // true ReactIs.typeOf() === ReactIs.ForwardRef; // true // Lazy -ReactIs.isLazy(); // true -ReactIs.typeOf() === ReactIs.Lazy; // true +ReactIs.isLazy(LazyComponent); // true +ReactIs.typeOf(LazyComponent) === ReactIs.Lazy; // true // Memo -ReactIs.isMemo(); // true -ReactIs.typeOf() === ReactIs.Memo; // true +ReactIs.isMemo(MemoComponent); // true +ReactIs.typeOf(MemoComponent) === ReactIs.Memo; // true // Suspense ReactIs.isForwardRef(); // true From f61e047579989394203e074e8c54064fabe56fab Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 10 Jan 2019 08:50:14 +0100 Subject: [PATCH 5/5] react-is: fix type guard return type --- types/react-is/index.d.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/types/react-is/index.d.ts b/types/react-is/index.d.ts index b7cce65e18..962d3e1a13 100644 --- a/types/react-is/index.d.ts +++ b/types/react-is/index.d.ts @@ -8,7 +8,12 @@ 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; @@ -18,8 +23,8 @@ 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 ReactElement; -export function isMemo(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;