Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 16.6 types #29989

Closed
Jessidhia opened this issue Oct 24, 2018 · 6 comments
Closed

React 16.6 types #29989

Jessidhia opened this issue Oct 24, 2018 · 6 comments

Comments

@Jessidhia
Copy link
Member

React 16.6 was released today: https://reactjs.org/blog/2018/10/23/react-v-16-6.html

I would have made this as a PR, but there is a problem with the new static contextType feature that I don't know how to solve. This is probably a TypeScript core problem.

First, the type of context is defined in class Component and marked as @deprecated (which triggers the deprecation tslint rule), but context is only deprecated if static contextType is not defined.

Second, the type of this.context depends on the type of static contextType, and there is no way I can think of, within TypeScript's generic system, declaring that in the types. While I can hack that into ComponentClass's definition, it wouldn't help actually subclassing Component correctly.

Probably the only solution that would work short term is removing the context: any declaration entirely, but it'd be a breaking change.


This is not the first time we hit limitations of the generic system in React; see getDerivedStateFromProps which had to be left out of Component's definition entirely because it'd just have to have any inputs and outputs anyway.

@artem-malko
Copy link
Contributor

@Kovensky you can use something like that for getDerivedStateFromProps:

export class Comp<P> extends React.Component<Props<P>> {
  public static getDerivedStateFromProps<P>(
    ...
  ) {
    ...
  }
}

@Jessidhia
Copy link
Member Author

The problem is that that P is just a hidden any. It is shadowing the P parameter of the class by creating its own local P parameter.

@artem-malko
Copy link
Contributor

Wow, bad news for me( Thank you for explanation.

@Finesse
Copy link
Contributor

Finesse commented Nov 22, 2018

What version of @types/react does contain 16.6 features but doesn't contain 16.7 features? There is no 16.6 version of @types/react in NPM.

@a7madgamal
Copy link

I'm looking at our company package.json and it's unexpectedly hard to install/update @types packages that matches the actual packages. I hope this change some day!

for now, any help on this issue would be great :)

@orta
Copy link
Collaborator

orta commented Jun 7, 2021

Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the @types modules in DefinitelyTyped.

To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the definitely-typed channel.

@orta orta closed this as completed Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants