JoshuaKGoldberg / JoshuaKGoldberg/TypeStat
Add React-specific incompleteTypes fixer(s) for state
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 47
- Avg merge
- 15h 55m
- Merged PRs (30d)
- 21
Description
### 🚀 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...
```tsx
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`
Contributor guide
Assessment
This issue has not been assessed yet.