From 2950b6bbe7fcb799bc7a4c9aceae6a125e54e95d Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Fri, 31 Mar 2017 09:00:17 -0400 Subject: [PATCH 1/2] Remove old warnings in react readme --- types/react/README.md | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/types/react/README.md b/types/react/README.md index c09dc060c2..7fb8f8ef15 100644 --- a/types/react/README.md +++ b/types/react/README.md @@ -1,30 +1,4 @@ ## Known Problems & Workarounds - -### **The type of `setState` is will be overly strict prior to TS 2.1.5** -Starting with TypeScript 2.1, its more correct than it used to be, with a caveat: optional parameters on state interfaces are no longer valid. This issue is corrected in 2.1.5 (and beyond) and thus `Pick` becomes ideal. - -```ts -interface FooState { - bar: string; - foo?: string; -} - -const defaultFooState: FooState = { - bar: "Hi", - foo: undefined, -}; - -class Foo extends React.Component<{}, FooState> { - public doStuff() { - this.setState(defaultFooState); - } -} -``` - -Prior to 2.1.5, this code will produce an error. The other way the types could be written (using `Partial<>` instead of `Pick<>`) would allow for you to set `undefined` to a parameter that is not allowed -to be `undefined`, which could lead to bugs. Users who want to keep optional state parameters should continue to use the hack of `setState({...} as any);` in versions prior to 2.1.5. - -(This caveat should be dropped after no later than March 2017, maybe sooner.) ### **The type of `cloneElement` is incorrect.** This is similar to the `setState` problem, in that `cloneElement(element, props)` should should accept a `props` object with a subset of the properties on `element.props`. There is an additional complication, however—React attributes, such as `key` and `ref`, should also be accepted in `props`, but should not exist on `element.props`. The "correct" way to model this, then, is with From 68094fa835391c491d06fa9196991f069eff137e Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Fri, 31 Mar 2017 09:11:31 -0400 Subject: [PATCH 2/2] Add myself as an author for react --- types/react/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 73cb0ae16f..69aaef3319 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for React v15.0 // Project: http://facebook.github.io/react/ -// Definitions by: Asana , AssureSign , Microsoft , John Reilly , Benoit Benezech , Patricio Zavolinsky , Digiguru +// Definitions by: Asana , AssureSign , Microsoft , John Reilly , Benoit Benezech , Patricio Zavolinsky , Digiguru , Eric Anderson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1