Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/create-react-class/create-react-class-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion types/react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions types/react/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down