utility-types
utility-types copied to clipboard
DeepReadonly should allow circular references in TS 3.9
Description
DeepReadonly
supported circular references in TS 3.8 but not TS 3.9.
Steps to Reproduce
The following works in TS 3.8.3, but fails in TS 3.9.5:
type NestedProps = {
first: {
second: {
name: string
children: NestedProps
}
}
}
type ReadonlyNestedProps = DeepReadonly<NestedProps>
The new error is:
Type of property 'children' circularly references itself in mapped type '_DeepReadonlyObject<{ name: string; children: NestedProps; }>'.ts(2615)
Expected behavior
It should work like it does in TS 3.8.
Suggested solution(s)
Not sure.
Project Dependencies
- Utility-Types Version: 3.10.0
- TypeScript Version: 3.9.5
- tsconfig.json: Doesn't appear to matter
I also ran into this issue today. It may be related to: https://github.com/microsoft/TypeScript/issues/38279
I verified this still repros under TS 3.9.6
. I'm really anxious to upgrade to TS 3.9. Anyone know of a workaround? Or alternative to this library's DeepReadonly
that is TS3.9 compatible? That's the main thing we use this library for.
@piotrwitek just wanted to mention that this is still an issue w/ the latest TS 4.0 beta.
Just in case anyone else is blocked on this, I switched to https://github.com/krzkaczor/ts-essentials which has drop-in replacements for everything I happen to use in utility-types
, is compatible w/ the latest typescript and is actively maintained.