TypeStat
TypeStat copied to clipboard
Add React-specific incompleteTypes fixer(s) for state
🚀 Feature Request
As a sibling to #745: there are some inferences that I'm finding to be very difficult, perhaps even possible, to represent in the type system. For example, React component classes technically can have different definitions for the class generic S(tate) and the member state type.
Also, in this example, it would be a lot of work to link the setState method to a new template type...
class MyComponent extends React.Component {
addToState = () => {
this.setState(previousState => ({
key: !previousState.key,
}));
};
}
Existing Behavior
Only what can be directly inferred from the type checker & language service will be... or, more accurately, the relatively easier to obtain subset of that 😂
Change Proposal
React is such a common use case for TypeScript conversions that even if all this is achievable using the type system, it's a bit too advanced for the types of fixes TypeStat and I can provide at the moment.
For state specifically:
- Merging the component class generic and member definition, if either is missing fields from the other
- Inferring the type of it from the state member and any calls to
setState