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

Make mobx-react compatible with TS 4.8+ #3565

Merged
merged 6 commits into from Nov 14, 2022
Merged

Conversation

kubk
Copy link
Collaborator

@kubk kubk commented Nov 4, 2022

Resolves: #3532

As @DanielSWolf wrote (thanks for that!): "This error occurs because TypeScript 4.8 is stricter than previous versions regarding unconstrained type parameters (see the blog entry announcing TypeScript 4.8)."

I confirm that adding constraint to the generic fixes the issue. Now the generic constraints are identical to IStoresToProps: https://github.com/mobxjs/mobx/blob/a39ce7fbe19f92348470ef71ad60555c37a5d5e9/packages/mobx-react/src/types/IStoresToProps.ts#L2+L6

I've chosen minor instead of patch because it's kinda BC break but at the same time it's a bugfix.

@changeset-bot
Copy link

changeset-bot bot commented Nov 4, 2022

🦋 Changeset detected

Latest commit: 13815ec

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

This PR includes changesets to release 1 package
Name Type
mobx-react Minor

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

@kubk kubk changed the title Mobx react strict inject Make mobx-react compatible with TS 4.8+ Nov 4, 2022
@kubk kubk marked this pull request as draft November 4, 2022 20:48
@DanielSWolf
Copy link

Regarding the failing tests: It seems to me that these tests have always been broken. TypeScript just didn't realize it until you fixed the types.

I've only skimmed the problems, but here are my best guesses:

  • This line should probably read inject(() => ({}))( (note the extra parentheses).
  • This line needs to explicitly specify the arrow function signature. This might work: const MainInjected = inject(({ store }: { store: { thing: number } }) => ({ thing: store.thing }))(Main)

@kubk kubk marked this pull request as ready for review November 14, 2022 17:41
@kubk
Copy link
Collaborator Author

kubk commented Nov 14, 2022

@DanielSWolf Thank you for the suggestions 👍 The issue with explicit signature is that we create a BC break. It looks like previously TS could infer the type correctly. But since inject is deprecated we can ask people to avoid using it completely in case of issues.

@kubk
Copy link
Collaborator Author

kubk commented Nov 14, 2022

@urugator The PR is ready to review 🙏

@urugator urugator merged commit 7aab223 into main Nov 14, 2022
@github-actions github-actions bot mentioned this pull request Nov 14, 2022
@kubk kubk deleted the mobx-react-strict-inject branch November 16, 2022 08:03
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

Successfully merging this pull request may close these issues.

Error "Type 'S' does not satisfy the constraint 'IValueMap'" with TypeScript 4.8 in mobx-react
3 participants