You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classAextendsComponent<{},{foo: string}>{render(){return<div>{this.state.foo}</div>;// Runtime error, `state` is null}}
I haven't done a thorough research, but doesn't seem like there's a way to address this through typings. So maybe a rule could be added, requiring state initialization, at least when it's explicitly typed:
classAextendsComponent<{},{foo: string}>{state=null// Compile-time error, can't be nullrender(){return<div>{this.state.foo}</div>;}}
Or require the state type to be nullable: This doesn't work with current typings:
classAextendsComponent<{},{foo: string}|null>{render(){return<div>{this.state.foo}</div>;// Compile-time error, `state` may be null}}
Thoughts?
The text was updated successfully, but these errors were encountered:
I think this is a good idea - definitely see this issue pop up now and again and it would be good to check against it. The TSLint team doesn't have a lot of bandwidth to write new rules at the moment, but will accept pull requests for this.
Right now, the following is possible:
I haven't done a thorough research, but doesn't seem like there's a way to address this through typings. So maybe a rule could be added, requiring state initialization, at least when it's explicitly typed:
Or require the state type to be nullable:This doesn't work with current typings:Thoughts?
The text was updated successfully, but these errors were encountered: