Add helper PropsWithChildren

This commit is contained in:
Vincent Langlet
2019-02-25 16:48:31 +01:00
parent b1285dace3
commit df31a02f00
2 changed files with 12 additions and 3 deletions
+5 -3
View File
@@ -468,7 +468,7 @@ declare namespace React {
type FC<P = {}> = FunctionComponent<P>;
interface FunctionComponent<P = {}> {
(props: P & { children?: ReactNode }, context?: any): ReactElement | null;
(props: PropsWithChildren<P>, context?: any): ReactElement | null;
propTypes?: WeakValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: Partial<P>;
@@ -476,7 +476,7 @@ declare namespace React {
}
interface RefForwardingComponent<T, P = {}> {
(props: P & { children?: ReactNode }, ref: Ref<T>): ReactElement | null;
(props: PropsWithChildren<P>, ref: Ref<T>): ReactElement | null;
propTypes?: WeakValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: Partial<P>;
@@ -722,6 +722,8 @@ declare namespace React {
: P
: P;
type PropsWithChildren<P> = P & { children?: ReactNode };
/**
* NOTE: prefer ComponentPropsWithRef, if the ref is forwarded,
* or ComponentPropsWithoutRef when refs are not supported.
@@ -747,7 +749,7 @@ declare namespace React {
function memo<P extends object>(
Component: SFC<P>,
propsAreEqual?: (prevProps: Readonly<P & { children?: ReactNode }>, nextProps: Readonly<P & { children?: ReactNode }>) => boolean
propsAreEqual?: (prevProps: Readonly<PropsWithChildren<P>>, nextProps: Readonly<PropsWithChildren<P>>) => boolean
): NamedExoticComponent<P>;
function memo<T extends ComponentType<any>>(
Component: T,
+7
View File
@@ -13,6 +13,7 @@ import TransitionGroup = require("react-addons-transition-group");
import update = require("react-addons-update");
import createReactClass = require("create-react-class");
import * as DOM from "react-dom-factories";
import { PropsWithChildren } from '../index';
// NOTE: forward declarations for tests
declare function setInterval(...args: any[]): any;
@@ -803,3 +804,9 @@ const sfc: React.SFC<any> = Memoized2;
// this $ExpectError is failing on TypeScript@next
// // $ExpectError Property '$$typeof' is missing in type
// const specialSfc2: React.SpecialSFC = props => null;
const propsWithChildren: PropsWithChildren<Props> = {
hello: "world",
foo: 42,
children: functionComponent,
};