mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
react: Children.map: replace overload with conditional type (#41771)
* `react`: `Children.map`: replace overload with conditional type * Document
This commit is contained in:
parent
b406bc6d23
commit
a09aa0ec09
5
types/react/index.d.ts
vendored
5
types/react/index.d.ts
vendored
@ -2788,9 +2788,8 @@ declare namespace React {
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
interface ReactChildren {
|
||||
map(children: null, fn: (child: never, index: number) => never): null;
|
||||
map(children: undefined, fn: (child: never, index: number) => never): undefined;
|
||||
map<T, C>(children: C | C[], fn: (child: C, index: number) => T): Array<Exclude<T, boolean | null | undefined>>;
|
||||
map<T, C>(children: C | C[], fn: (child: C, index: number) => T):
|
||||
C extends null | undefined ? C : Array<Exclude<T, boolean | null | undefined>>;
|
||||
forEach<C>(children: C | C[], fn: (child: C, index: number) => void): void;
|
||||
count(children: any): number;
|
||||
only<C>(children: C): C extends any[] ? never : C;
|
||||
|
||||
@ -514,6 +514,7 @@ onlyChild = React.Children.only([null, [[["Hallo"], true]], false]); // error
|
||||
const childrenToArray: Array<Exclude<React.ReactNode, boolean | null | undefined>> = React.Children.toArray(children);
|
||||
|
||||
declare const numberChildren: number[];
|
||||
declare const nodeChildren: React.ReactNode;
|
||||
declare const elementChildren: JSX.Element[];
|
||||
declare const mixedChildren: Array<JSX.Element | string>;
|
||||
declare const singlePluralChildren: JSX.Element | JSX.Element[];
|
||||
@ -533,6 +534,9 @@ const mappedChildrenArray4 = React.Children.map(mixedChildren, elementOrString =
|
||||
const mappedChildrenArray5 = React.Children.map(singlePluralChildren, element => element.key);
|
||||
// $ExpectType string[]
|
||||
const mappedChildrenArray6 = React.Children.map(renderPropsChildren, element => element.name);
|
||||
// The return type may not be an array
|
||||
// $ExpectError
|
||||
const mappedChildrenArray7 = React.Children.map(nodeChildren, node => node).map;
|
||||
|
||||
//
|
||||
// Example from http://facebook.github.io/react/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user