From df31a02f0005cdee2f620d7c18c768c6c6e3ac2d Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 25 Feb 2019 16:48:31 +0100 Subject: [PATCH] Add helper PropsWithChildren --- types/react/index.d.ts | 8 +++++--- types/react/test/index.ts | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 97adab18d4..f7b7310d7d 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -468,7 +468,7 @@ declare namespace React { type FC

= FunctionComponent

; interface FunctionComponent

{ - (props: P & { children?: ReactNode }, context?: any): ReactElement | null; + (props: PropsWithChildren

, context?: any): ReactElement | null; propTypes?: WeakValidationMap

; contextTypes?: ValidationMap; defaultProps?: Partial

; @@ -476,7 +476,7 @@ declare namespace React { } interface RefForwardingComponent { - (props: P & { children?: ReactNode }, ref: Ref): ReactElement | null; + (props: PropsWithChildren

, ref: Ref): ReactElement | null; propTypes?: WeakValidationMap

; contextTypes?: ValidationMap; defaultProps?: Partial

; @@ -722,6 +722,8 @@ declare namespace React { : P : P; + type PropsWithChildren

= 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

( Component: SFC

, - propsAreEqual?: (prevProps: Readonly

, nextProps: Readonly

) => boolean + propsAreEqual?: (prevProps: Readonly>, nextProps: Readonly>) => boolean ): NamedExoticComponent

; function memo>( Component: T, diff --git a/types/react/test/index.ts b/types/react/test/index.ts index d4fee49d30..fffde44f52 100644 --- a/types/react/test/index.ts +++ b/types/react/test/index.ts @@ -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 = Memoized2; // this $ExpectError is failing on TypeScript@next // // $ExpectError Property '$$typeof' is missing in type // const specialSfc2: React.SpecialSFC = props => null; + +const propsWithChildren: PropsWithChildren = { + hello: "world", + foo: 42, + children: functionComponent, +};