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

replace the deprecated react type definition with recommended type def #2741

Closed
wants to merge 1 commit into from
Closed

replace the deprecated react type definition with recommended type def #2741

wants to merge 1 commit into from

Conversation

iChenLei
Copy link
Member

Code change checklist

  • Added/updated unit tests
  • Updated /docs. For new functionality, at least API.md should be updated
  • Verified that there is no significant performance drop (npm run perf)

PR Backgroud

When I try to solve this problem #2721 , I noticed that mobx-react(and lite) source code use
deprecated react type definition, Such as RefForwardingComponent React.Props
and StatelessComponent , so I created a PR to replace these with official recommended type def.

@types/react source code

StatelessComponent

  /**
   * @deprecated as of recent React versions, function components can no
   * longer be considered 'stateless'. Please use `FunctionComponent` instead.
   *
   * @see [React Hooks](https://reactjs.org/docs/hooks-intro.html)
   */
  type StatelessComponent<P = {}> = FunctionComponent<P>;

RefForwardingComponent

  /**
   * @deprecated Use ForwardRefRenderFunction. forwardRef doesn't accept a
   *             "real" component.
   */
  interface RefForwardingComponent <T, P = {}> extends ForwardRefRenderFunction<T, P> {}

React.Props

  /**
   * @deprecated. This was used to allow clients to pass `ref` and `key`
   * to `createElement`, which is no longer necessary due to intersection
   * types. If you need to declare a props object before passing it to
   * `createElement` or a factory, use `ClassAttributes<T>`:
   *
   * ```ts
   * var b: Button | null;
   * var props: ButtonProps & ClassAttributes<Button> = {
   *     ref: b => button = b, // ok!
   *     label: "I'm a Button"
   * };
   * ```
   */
  interface Props<T> {
      children?: ReactNode;
      key?: Key;
      ref?: LegacyRef<T>;
  }

@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2021

🦋 Changeset detected

Latest commit: 4e863ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
mobx-react Patch
mobx-react-lite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@danielkcz
Copy link
Contributor

danielkcz commented Jan 23, 2021

Thanks, I will keep it open for now. In my opinion, as long as the last package version has old types included (even deprecated), it's no harm to use those. The other way around we would be forcing users to type package versions that include new types and that would be a breaking change.

Or did you also discover that old types would be causing some issues? In that case, I would ask you to include test cases for that.

@danielkcz danielkcz added ✋ on hold 🎁 mobx-react Issue or PR related to mobx-react package 🎁 mobx-react-lite Issue or PR related to mobx-react-lite package labels Jan 23, 2021
@iChenLei
Copy link
Member Author

Yeah, You consider much more code change impact as a mobx maintianer. mobx-react(and lite) are very popular react ecosystem library and have many real user around the world, we need care any change even it's type defintion. on hold is a good choice, I will refocus on this PR when @types/react remove these deprecated type def code or old types would be causing some issues(will add unit test). Anyway , thanks for your advices. 😄

@akphi
Copy link

akphi commented Apr 23, 2022

Hi, brought here by #3370. With react 18 is this the right time to do this upgrade now?

@spamforhope
Copy link

spamforhope commented Apr 26, 2022

Yes, react 18 removed deprecated parts and now mobx-react-lite typings doesn't work at all.
Please, merge those changes and make new patch release ASAP

@kubk
Copy link
Collaborator

kubk commented Apr 26, 2022

@spamforhope Consider using patch-package as a temporary solution. The adaptation to React 18 is being worked on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎁 mobx-react Issue or PR related to mobx-react package 🎁 mobx-react-lite Issue or PR related to mobx-react-lite package ✋ on hold
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants