revert(react): remove null union from state which is a BC (#26946)

This commit is contained in:
Martin Hochel 2018-06-29 14:44:58 +02:00 committed by John Reilly
parent 014d59e291
commit a5b0278214
3 changed files with 5 additions and 11 deletions

View File

@ -56,7 +56,7 @@ const ClassicComponent: React.ClassicComponentClass<Props> = createReactClass<Pr
shouldComponentUpdate(this: React.ClassicComponent<Props, State>, nextProps, nextState) {
const newFoo: string = nextProps.foo;
const newBar: number = nextState.bar;
return newFoo !== this.props.foo && newBar !== this.state!.bar;
return newFoo !== this.props.foo && newBar !== this.state.bar;
},
statics: {
test: 1

View File

@ -306,7 +306,7 @@ declare namespace React {
// In the future, if we can define its call signature conditionally
// on the existence of `children` in `P`, then we should remove this.
readonly props: Readonly<{ children?: ReactNode }> & Readonly<P>;
state: null | Readonly<S>;
state: Readonly<S>;
/**
* @deprecated
* https://reactjs.org/docs/legacy-context.html

View File

@ -59,14 +59,7 @@ declare const container: Element;
inputValue: string;
seconds: number;
}
/**
* This is a "pre EcmaScript class property era" style of setting state within constructor.
* This occurs also if you need to provide som logic before mounting your component.
* To mitigate this error you need to provide state property definition upfront.
*/
class SettingStateFromCtorComponent extends React.Component<Props, State, Snapshot> {
// uncomenting this fixes the error :)
// state: State;
constructor(props: Props) {
super(props);
// $ExpectError
@ -78,16 +71,17 @@ declare const container: Element;
}
class BadlyInitializedState extends React.Component<Props, State, Snapshot> {
// ExpectError -> this throws error on TS 2.6
// $ExpectError -> this throws error on TS 2.6 uncomment once TS requirement is TS >= 2.7
// state = {
// secondz: 0,
// inputValuez: 'hello'
// };
render() { return null; }
}
class BetterPropsAndStateChecksComponent extends React.Component<Props, State, Snapshot> {
render() { return null; }
componentDidMount() {
// $ExpectError
// $ExpectError -> this will be true in next BC release where state is gonna be `null | Readonly<S>`
console.log(this.state.inputValue);
}
mutateState() {