You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DeepReadonly type fails to compile on typescript 3.1.1+ #29566
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
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 readonly modifier to tuples and arrays and you will not need any special handling for them. This will work as expected (as far as I can tell) in 3.4 (you can try it out with npm install typescript@next:
Activity
masterkidan commentedon Jan 24, 2019
I understand this may be by design, but is there a way to achieve the same with newer versions of typescript?
Dean177 commentedon Mar 4, 2019
Mukundan Kidambi (@masterkidan) looks like this is due to the tuple types, without those your code works as expected
Playground link
masterkidan commentedon Mar 8, 2019
Dean Merchant (@Dean177) : Thanks!, is there a way to make this work without removing support for Tuples?
dragomirtitian commentedon Mar 8, 2019
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
readonlymodifier to tuples and arrays and you will not need any special handling for them. This will work as expected (as far as I can tell) in 3.4 (you can try it out withnpm install typescript@next:aleclarson commentedon Mar 8, 2019
Immer has a "deep readonly" type called
Immutable(see here) that works fine in 3.1+(No support for
Map,Set, orPromiselike the OP, but you can add that yourself rather easily)