-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Error "Type 'S' does not satisfy the constraint 'IValueMap'" with TypeScript 4.8 in mobx-react #3532
Comments
Could you describe the necessity of using Inject over React Context? The second one is a stable alternative to inject: https://github.com/mobxjs/mobx/tree/main/packages/mobx-react#provider-and-inject
|
I'm not using Inject in any way. It just happens to be part of |
@DanielSWolf Ok, thank you, I'll test |
Also running into this issue, I pulled the mobx repository and was able to reproduce it by bumping typescript and just running a build:
If you follow the tsc suggestions it simply changes: export function inject<S, P, I, C>(
fn: IStoresToProps<S, P, I, C>
): <T extends IReactComponent>(target: T) => T & IWrappedComponent<P> to export function inject<
S extends IValueMap,
P extends IValueMap,
I extends IValueMap,
C extends IValueMap
>(
fn: IStoresToProps<S, P, I, C>
): <T extends IReactComponent>(target: T) => T & IWrappedComponent<P> After that, the build works as expected, although the suggested updates seems a bit odd, unsure what you're actually expecting here as a base constraint. |
I'm finding the same issue when using typescript |
This issue has been fixed in We're using version 6.x. Given that the README states that version 6.x is "actively maintained", is there a chance of a backport? |
@DanielSWolf Yes, the fix was applied only for 7. Unfortunately the README is outdated. The sentence "There are currently two actively maintained versions of mobx-react:" refers to old versions v5 and v6: mobxjs/mobx-react@70544ba This is how it looked like: https://github.com/mobxjs/mobx-react/blob/79a5dc1a2cdea88e8a213a4b4e16bb14e499631d/README.md Currently we publish only 7 from the monorepo and don't have any active branch or project related to version 6. Possible solutions for you are patch-package or updating your major version of mobx-react. Hope it helps. |
@kubk Thanks for the clarification! |
@DanielSWolf We're updating the README: #3577 |
Intended outcome:
mobx-react
6.3.1 compiles with TypeScript 4.8Actual outcome:
When using
mobx-react
6.3.1 in a project that uses TypeScript 4.8, I get the following compiler error:This error occurs because TypeScript 4.8 is stricter than previous versions regarding unconstrained type parameters (see the blog entry announcing TypeScript 4.8).
The fix is to change
function inject<S, P, I, C>
tofunction inject<S extends IValueMap, P extends IValueMap, I extends IValueMap, C extends IValueMap>
.How to reproduce the issue:
Use
mobx-react
6.3.1 in any project that uses TypeScript 4.8.Versions
The text was updated successfully, but these errors were encountered: