utility-types icon indicating copy to clipboard operation
utility-types copied to clipboard

DeepReadonly should allow circular references in TS 3.9

Open tony-scio opened this issue 4 years ago • 4 comments

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

tony-scio avatar Jun 04 '20 19:06 tony-scio

I also ran into this issue today. It may be related to: https://github.com/microsoft/TypeScript/issues/38279

garycourt avatar Jun 17 '20 23:06 garycourt

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.

tony-scio avatar Jul 02 '20 13:07 tony-scio

@piotrwitek just wanted to mention that this is still an issue w/ the latest TS 4.0 beta.

tony-scio avatar Jul 17 '20 15:07 tony-scio

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.

tony-scio avatar Jul 19 '20 12:07 tony-scio