forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move experimental APIs to stable for React 18
See facebook/react#21488.
- Loading branch information
Showing
9 changed files
with
186 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
}, | ||
"files": [ | ||
"index.d.ts", | ||
"test/react-is-tests.tsx", | ||
"test/next-tests.tsx" | ||
"test/react-is-tests.tsx" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Type definitions for react-is 17.0 | ||
// 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 | ||
|
||
// NOTE: Users of the React 18 alpha should add a reference | ||
// to 'react-is/next' in their project. See next.d.ts's top comment | ||
// for reference and documentation on how exactly to do it. | ||
|
||
export as namespace ReactIs; | ||
|
||
import { | ||
LazyExoticComponent, | ||
MemoExoticComponent, | ||
ReactElement, | ||
ElementType | ||
} from "react"; | ||
|
||
export function typeOf(value: any): symbol | undefined; | ||
export function isValidElementType(value: any): value is ElementType; | ||
export function isAsyncMode(value: any): value is ReactElement; | ||
export function isContextConsumer(value: any): value is ReactElement; | ||
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<any>; | ||
export function isMemo(value: any): value is MemoExoticComponent<any>; | ||
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; | ||
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; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import * as ReactIs from 'react-is'; | ||
|
||
// Below is taken from README of react-is | ||
// Determining if a Component is Valid | ||
|
||
interface CompProps { | ||
forwardedRef: React.Ref<any>; | ||
children?: React.ReactNode | undefined; | ||
} | ||
|
||
class ClassComponent extends React.Component<CompProps> { | ||
render() { | ||
return React.createElement('div'); | ||
} | ||
} | ||
|
||
const FunctionComponent = () => React.createElement('div'); | ||
|
||
const ForwardRefComponent = React.forwardRef((props, ref) => | ||
React.createElement(ClassComponent, { forwardedRef: ref, ...props }) | ||
); | ||
|
||
const LazyComponent = React.lazy(() => | ||
Promise.resolve({ default: ForwardRefComponent }) | ||
); | ||
|
||
const MemoComponent = React.memo(FunctionComponent); | ||
|
||
const Context = React.createContext(false); | ||
|
||
ReactIs.isValidElementType('div'); // true | ||
ReactIs.isValidElementType(ClassComponent); // true | ||
ReactIs.isValidElementType(FunctionComponent); // true | ||
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 | ||
|
||
// AsyncMode - unstable_AsyncMode is not implemented in @types/react yet | ||
// ReactIs.isAsyncMode(<React.unstable_AsyncMode />); // true | ||
// ReactIs.typeOf(<React.unstable_AsyncMode />) === ReactIs.AsyncMode; // true | ||
|
||
// Context | ||
const ThemeContext = React.createContext('blue'); | ||
|
||
ReactIs.isContextConsumer(<ThemeContext.Consumer children={FunctionComponent} />); // true | ||
ReactIs.isContextProvider(<ThemeContext.Provider children={<FunctionComponent />} value='black' />); // true | ||
ReactIs.typeOf(<ThemeContext.Consumer children={FunctionComponent} />) === ReactIs.ContextConsumer; // true | ||
ReactIs.typeOf(<ThemeContext.Provider children={<FunctionComponent />} value='black' />) === ReactIs.ContextProvider; // true | ||
|
||
// Element | ||
ReactIs.isElement(<div />); // true | ||
ReactIs.typeOf(<div />) === ReactIs.Element; // true | ||
|
||
// Fragment | ||
ReactIs.isFragment(<></>); // true | ||
ReactIs.typeOf(<></>) === ReactIs.Fragment; // true | ||
|
||
// Portal | ||
const div = document.createElement('div'); | ||
const portal = ReactDOM.createPortal(<div />, div); | ||
|
||
ReactIs.isPortal(portal); // true | ||
ReactIs.typeOf(portal) === ReactIs.Portal; // true | ||
|
||
// StrictMode | ||
ReactIs.isStrictMode(<React.StrictMode />); // true | ||
ReactIs.typeOf(<React.StrictMode />) === ReactIs.StrictMode; // true | ||
|
||
// Verify typeOf accepts any type of value (taken from tests of react-is) | ||
ReactIs.typeOf('abc') === undefined; | ||
ReactIs.typeOf(true) === undefined; | ||
ReactIs.typeOf(123) === undefined; | ||
ReactIs.typeOf({}) === undefined; | ||
ReactIs.typeOf(null) === undefined; | ||
ReactIs.typeOf(undefined) === undefined; | ||
|
||
// ForwardRef | ||
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={<FunctionComponent />} />); // true | ||
ReactIs.typeOf(<React.Suspense fallback={<FunctionComponent />} />) === ReactIs.Suspense; // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es6", | ||
"dom" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"baseUrl": "../../", | ||
"typeRoots": [ | ||
"../../" | ||
], | ||
"paths": { | ||
"react": ["react/v17"], | ||
"react-dom": ["react-dom/v17"], | ||
"react-is/*": ["react-is/v17/*"] | ||
}, | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictFunctionTypes": true, | ||
"jsx": "preserve" | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"test/react-is-tests.tsx", | ||
"test/next-tests.tsx" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "@definitelytyped/dtslint/dt.json" } |