-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Typescript error: Type 'unknown' is not assignable to type 'never' #4076
Comments
This really isn't a meaningful issue report that we can act on. I don't know what the rest of this error message is, and I don't know how this error message actually relates to Redux at all. If anything, this is likely related to use of Please follow our recommended patterns for using Redux with TypeScript, including use of Redux Toolkit's If you're still having issues after that, please provide a reproduction of the problem as either a CodeSandbox or a Github repo that demonstrates what's happening. |
The error is not on the configureStore but on createStore. |
As I said, this is likely due to your hardcoded TS return type or the use of |
I removed the hardcoded return type and I still have the issue. export type PreloadedState<S> = Required<S> extends {
[$CombinedState]: undefined
}
? S extends CombinedState<infer S1>
? {
[K in keyof S1]?: S1[K] extends object ? PreloadedState<S1[K]> : S1[K]
}
: never
: {
[K in keyof S]: S[K] extends string | number | boolean | symbol
? S[K]
: PreloadedState<S[K]>
} by modifying this typing like that: export type PreloadedState<S> = Required<S> extends EmptyObject
? S extends CombinedState<infer S1>
? {
[K in keyof S1]?: S1[K] extends object ? PreloadedState<S1[K]> : S1[K]
}
: unknown
: {
[K in keyof S]: S[K] extends string | number | boolean | symbol
? S[K]
: PreloadedState<S[K]>
} typescript is not complaining any longer. |
Please provide a code snippet that actually reproduces the issue - the code you have there runs just 100% fine in TypeScript, as you can see in this TS playground |
Hello, I finally pinpointed the source of the issue. With strictNullChecks: true, test is of type string, and with strictNullChecks: false, test is of type number type test = unknown extends {} ? number : string; So the output of PreloadedState changes with the value of strictNullChecks too. For example: With a playground showing the typing error: TS playground |
That part is pretty natural. If you set |
I didn't disable it, I enable it. |
Please see if #4078 resolves your issue |
It resolves it 👍 |
What is the current behavior?
Redux set never as type instead of unknown:
The types of 'router.location.state' are incompatible between these types.
Type 'unknown' is not assignable to type 'never'.
Steps to Reproduce
What is the expected behavior?
Use unknown instead of never
Environment Details
Redux 4.1.0
Chrome
Windows 10
Did this work in previous versions of Redux? Yes
The text was updated successfully, but these errors were encountered: