-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
DeepReadonly type fails to compile on typescript 3.1.1+ #29566
Comments
I understand this may be by design, but is there a way to achieve the same with newer versions of typescript? |
@masterkidan looks like this is due to the tuple types, without those your code works as expected |
@Dean177 : Thanks!, is there a way to make this work without removing support for Tuples? |
Actually I think you are better off wating for 3.4 and Improved support for read-only arrays and tuples (#29435). With this new feature mapped types will apply the export type DeepReadonly<T> =
T extends Map<infer U, infer V> ? ReadonlyMap<DeepReadonlyObject<U>, DeepReadonlyObject<V>> :
T extends Set<infer U> ? ReadonlySet<DeepReadonlyObject<U>> :
T extends Promise<infer U> ? Promise<DeepReadonlyObject<U>> :
T extends Function ? T : DeepReadonlyObject<T>
type DeepReadonlyObject<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> } |
Immer has a "deep readonly" type called (No support for |
TypeScript Version: 3.1.1+
Search Terms: DeepReadonly
Code
Expected behavior:
This used to work as of typescript 3.0.1
Actual behavior:
In typescript 3.1.1 a new error is thrown saying that the type is cyclical
In typescript 3.2+ the above error, instead ends up casting the type as
any
Playground Link:
Here's a gist with tests for the type
https://gist.github.com/masterkidan/7322752f569b1bba53e0426266768623
Playground link
Related Issues:
#27421
#13923
#26236
The text was updated successfully, but these errors were encountered: