Title: DeepReadonly type fails to compile on typescript 3.1.1+ · Issue #29566 · microsoft/TypeScript · GitHub
Open Graph Title: DeepReadonly type fails to compile on typescript 3.1.1+ · Issue #29566 · microsoft/TypeScript
X Title: DeepReadonly type fails to compile on typescript 3.1.1+ · Issue #29566 · microsoft/TypeScript
Description: TypeScript Version: 3.1.1+ Search Terms: DeepReadonly Code export type Primitive = string | number | boolean | undefined | null | Function | symbol; export type DeepReadonly
Open Graph Description: TypeScript Version: 3.1.1+ Search Terms: DeepReadonly Code export type Primitive = string | number | boolean | undefined | null | Function | symbol; export type DeepReadonly
X Description: TypeScript Version: 3.1.1+ Search Terms: DeepReadonly Code export type Primitive = string | number | boolean | undefined | null | Function | symbol; export type DeepReadonly<T> = T extends [i...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/29566
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"DeepReadonly type fails to compile on typescript 3.1.1+","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨 -->\r\n\u003c!--\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker.\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the CONTRIBUTING guidelines: https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n-->\r\n\r\n\u003c!-- If you have a QUESTION:\r\n THIS IS NOT A FORUM FOR QUESTIONS.\r\n Ask questions at http://stackoverflow.com/questions/tagged/typescript\r\n or https://gitter.im/Microsoft/TypeScript\r\n-->\r\n\r\n\u003c!-- If you have a SUGGESTION:\r\n Most suggestion reports are duplicates, please search extra hard before logging a new suggestion.\r\n See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md\r\n-->\r\n\r\n\u003c!-- If you have a BUG:\r\n Please fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.1.1+\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** DeepReadonly\r\n\r\n**Code**\r\n\r\n```ts\r\nexport type Primitive = string | number | boolean | undefined | null | Function | symbol;\r\nexport type DeepReadonly\u003cT> =\r\n T extends [infer A] ? DeepReadonlyObject\u003c[A]> :\r\n T extends [infer A, infer B] ? DeepReadonlyObject\u003c[A, B]> :\r\n T extends [infer A, infer B, infer C] ? DeepReadonlyObject\u003c[A, B, C]> :\r\n T extends [infer A, infer B, infer C, infer D] ? DeepReadonlyObject\u003c[A, B, C, D]> :\r\n T extends [infer A, infer B, infer C, infer D, infer E] ? DeepReadonlyObject\u003c[A, B, C, D, E]> :\r\n T extends [infer A, infer B, infer C, infer D, infer E, infer F] ? DeepReadonlyObject\u003c[A, B, C, D, E, F]> :\r\n T extends [infer A, infer B, infer C, infer D, infer E, infer F, infer G] ? DeepReadonlyObject\u003c[A, B, C, D, E, F, G]> :\r\n T extends Map\u003cinfer U, infer V> ? ReadonlyMap\u003cDeepReadonlyObject\u003cU>, DeepReadonlyObject\u003cV>> :\r\n T extends Set\u003cinfer U> ? ReadonlySet\u003cDeepReadonlyObject\u003cU>> :\r\n T extends Promise\u003cinfer U> ? Promise\u003cDeepReadonlyObject\u003cU>> :\r\n T extends Primitive ? T :\r\n T extends (infer A)[] ? DeepReadonlyArray\u003cA> :\r\n DeepReadonlyObject\u003cT>;\r\n\r\ninterface DeepReadonlyArray\u003cT> extends ReadonlyArray\u003cDeepReadonly\u003cT>> {}\r\ntype DeepReadonlyObject\u003cT> = { readonly [P in keyof T]: DeepReadonly\u003cT[P]> }\r\n```\r\n\r\n**Expected behavior:**\r\nThis used to work as of typescript 3.0.1\r\n\r\n**Actual behavior:**\r\nIn typescript 3.1.1 a new error is thrown saying that the type is cyclical\r\nIn typescript 3.2+ the above error, instead ends up casting the type as `any`\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior --> \r\nHere's a gist with tests for the type \r\nhttps://gist.github.com/masterkidan/7322752f569b1bba53e0426266768623\r\n\r\n[Playground link](\u003chttps://www.typescriptlang.org/play/index.html#src=export%20type%20Primitive%20%3D%20string%20%7C%20number%20%7C%20boolean%20%7C%20undefined%20%7C%20null%20%7C%20Function%20%7C%20symbol%3B%0D%0Aexport%20type%20DeepReadonly%3CT%3E%20%3D%0D%0A%20%20T%20extends%20%5Binfer%20A%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3F%20DeepReadonlyObject%3C%5BA%5D%3E%20%3A%0D%0A%20%20T%20extends%20%5Binfer%20A%2C%20infer%20B%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3F%20DeepReadonlyObject%3C%5BA%2C%20B%5D%3E%20%3A%0D%0A%20%20T%20extends%20%5Binfer%20A%2C%20infer%20B%2C%20infer%20C%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3F%20DeepReadonlyObject%3C%5BA%2C%20B%2C%20C%5D%3E%20%3A%0D%0A%20%20T%20extends%20%5Binfer%20A%2C%20infer%20B%2C%20infer%20C%2C%20infer%20D%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3F%20DeepReadonlyObject%3C%5BA%2C%20B%2C%20C%2C%20D%5D%3E%20%3A%0D%0A%20%20T%20extends%20%5Binfer%20A%2C%20infer%20B%2C%20infer%20C%2C%20infer%20D%2C%20infer%20E%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3F%20DeepReadonlyObject%3C%5BA%2C%20B%2C%20C%2C%20D%2C%20E%5D%3E%20%3A%0D%0A%20%20T%20extends%20%5Binfer%20A%2C%20infer%20B%2C%20infer%20C%2C%20infer%20D%2C%20infer%20E%2C%20infer%20F%5D%20%20%20%20%20%20%20%20%20%20%3F%20DeepReadonlyObject%3C%5BA%2C%20B%2C%20C%2C%20D%2C%20E%2C%20F%5D%3E%20%3A%0D%0A%20%20T%20extends%20%5Binfer%20A%2C%20infer%20B%2C%20infer%20C%2C%20infer%20D%2C%20infer%20E%2C%20infer%20F%2C%20infer%20G%5D%20%3F%20DeepReadonlyObject%3C%5BA%2C%20B%2C%20C%2C%20D%2C%20E%2C%20F%2C%20G%5D%3E%20%3A%0D%0A%20%20T%20extends%20Map%3Cinfer%20U%2C%20infer%20V%3E%20%3F%20ReadonlyMap%3CDeepReadonlyObject%3CU%3E%2C%20DeepReadonlyObject%3CV%3E%3E%20%3A%0D%0A%20%20T%20extends%20Set%3Cinfer%20U%3E%20%3F%20ReadonlySet%3CDeepReadonlyObject%3CU%3E%3E%20%3A%0D%0A%20%20T%20extends%20Promise%3Cinfer%20U%3E%20%3F%20Promise%3CDeepReadonlyObject%3CU%3E%3E%20%3A%0D%0A%20%20T%20extends%20Primitive%20%3F%20T%20%3A%0D%0A%20%20T%20extends%20(infer%20A)%5B%5D%20%20%20%20%20%20%20%20%20%20%20%3F%20DeepReadonlyArray%3CA%3E%20%3A%0D%0A%20%20DeepReadonlyObject%3CT%3E%3B%0D%0A%0D%0Ainterface%20DeepReadonlyArray%3CT%3E%20extends%20ReadonlyArray%3CDeepReadonly%3CT%3E%3E%20%7B%7D%0D%0Atype%20DeepReadonlyObject%3CT%3E%20%3D%20%7B%20readonly%20%5BP%20in%20keyof%20T%5D%3A%20DeepReadonly%3CT%5BP%5D%3E%20%7D%0D%0A%0D%0Atype%20DeepTestType%20%3D%20DeepReadonly%3C%7B%0D%0A%20%20a%3A%20string%0D%0A%20%20b%3A%20number%5B%5D%0D%0A%20%20c%3A%20%7B%20d%3A%20string%2C%20e%3A%20number%5B%5D%2C%20f%3A%20%5Bnumber%2C%20%7B%20g%3A%20string%2C%20h%3A%20number%20%7D%5D%20%7D%0D%0A%20%20i%3A%20%5Bnumber%2C%20string%2C%20boolean%5D%0D%0A%20%20j%3A%20%7B%20id%3A%20number%2C%20name%3A%20string%20%7D%5B%5D%0D%0A%20%20k%3A%20Set%3Cnumber%3E%0D%0A%20%20l%3A%20Map%3C%7B%20id%3A%20number%2C%20name%3A%20string%20%7D%2C%20%7B%20age%3A%20number%20%7D%3E%0D%0A%20%20m()%3A%20void%0D%0A%20%20n%3A%20Symbol%0D%0A%20%20o%3A%20Promise%3Cvoid%3E%0D%0A%20%20p%3A%20Promise%3C%7B%20q%3A%20%7B%20r%3A%20number%20%7D%7D%3E%0D%0A%7D%3E%0D%0A%0D%0Aconst%20record%20%3D%20%7B%20id%3A%20123%2C%20name%3A%20'zxc'%20%7D%0D%0A%0D%0Aconst%20deepTest%3A%20DeepTestType%20%3D%20%7B%0D%0A%20%20a%3A%20'asdf'%2C%0D%0A%20%20b%3A%20%5B123%2C%20234%5D%2C%0D%0A%20%20c%3A%20%7B%20d%3A%20'zxc'%2C%20e%3A%20%5B1%2C%202%2C%203%5D%2C%20f%3A%20%5B1%2C%20%7B%20g%3A%20'iop'%2C%20h%3A%20789%20%7D%5D%20%7D%2C%0D%0A%20%20i%3A%20%5B1%2C%20'a'%2C%20true%5D%2C%0D%0A%20%20j%3A%20%5B%7B%20id%3A%201%2C%20name%3A%20'c'%20%7D%5D%2C%0D%0A%20%20k%3A%20new%20Set(%5B1%2C%202%2C%203%5D)%2C%0D%0A%20%20l%3A%20new%20Map(%5B%0D%0A%20%20%20%20%5Brecord%2C%20%7B%20age%3A%20789%20%7D%5D%0D%0A%20%20%5D)%2C%0D%0A%20%20m()%20%7B%20console.log('m%20says%20mmm')%20%7D%2C%0D%0A%20%20n%3A%20Symbol()%2C%0D%0A%20%20o%3A%20Promise.resolve()%0D%0A%7D%0D%0A%0D%0Aconsole.log(deepTest.a)%20%2F%2F%20pass%0D%0AdeepTest.a%20%3D%20'zxcv'%20%2F%2F%20fail%0D%0A%0D%0Aconsole.log(deepTest.b%5B0%5D)%20%2F%2F%20pass%0D%0AdeepTest.b%5B0%5D%20%3D%20789%20%2F%2F%20fail%0D%0AdeepTest.b%5B1%5D%20%3D%20890%20%2F%2F%20fail%0D%0A%0D%0Aconsole.log(deepTest.c.d)%20%2F%2F%20pass%0D%0AdeepTest.c.d%20%3D%20'asd'%20%2F%2F%20fail%0D%0A%0D%0Aconsole.log(deepTest.c.f%5B0%5D)%20%2F%2F%20pass%0D%0AdeepTest.c.f%5B0%5D%20%3D%20'asd'%20%2F%2F%20fail%0D%0A%0D%0Aconsole.log(deepTest.c.f%5B1%5D.g)%20%2F%2F%20pass%0D%0AdeepTest.c.f%5B1%5D.g%20%3D%20'zxc'%20%2F%2F%20fail%0D%0A%0D%0Aconsole.log(deepTest.i%5B1%5D)%20%2F%2F%20pass%0D%0Aconsole.log(Math.pow(deepTest.i%5B0%5D%2C%201))%20%20%2F%2F%20pass%20(doesn't%20union%20tuple)%0D%0AdeepTest.i%5B1%5D%20%3D%20'zxc'%20%2F%2F%20fail%0D%0A%0D%0Aconsole.log(deepTest.j%5B0%5D.id)%20%2F%2F%20pass%0D%0AdeepTest.j%5B0%5D.id%20%3D%20789%20%2F%2F%20fail%0D%0A%0D%0Aconsole.log(deepTest.k)%20%2F%2F%20pass%0D%0AdeepTest.k.add(789)%20%2F%2F%20fail%0D%0A%0D%0Aconsole.log(deepTest.l.get(record).age)%20%2F%2F%20pass%0D%0AdeepTest.l.get(record).age%20%3D%201%20%2F%2F%20fail%0D%0AdeepTest.l.set(%7B%20id%3A%20789%2C%20name%3A%20'blah'%20%7D%2C%20%7B%20age%3A%20567%20%7D)%20%2F%2F%20fail%0D%0Alet%20keys%20%3D%20deepTest.l.keys()%3B%0D%0Alet%20key%20%3D%20keys.next()%0D%0Awhile(key)%20%7B%0D%0A%20%20console.log(key.value.name)%20%2F%2F%20pass%0D%0A%20%20key.value.name%20%3D%20'zxc'%20%2F%2F%20fail%0D%0A%20%20key%20%3D%20keys.next()%3B%0D%0A%7D%20%0D%0A%0D%0AdeepTest.m()%20%2F%2F%20pass%0D%0AdeepTest.m%20%3D%20()%20%3D%3E%20console.log('n%20says%20nnn')%20%2F%2F%20fail%0D%0A%0D%0Aconsole.log(deepTest.n)%20%2F%2F%20pass%0D%0AdeepTest.n%20%3D%20Symbol()%20%2F%2F%20fail%0D%0A%0D%0AdeepTest.o.then(()%20%3D%3E%20console.log('hello'))%20%2F%2F%20pass%0D%0AdeepTest.o%20%3D%20Promise.resolve()%20%2F%2F%20fail%0D%0AdeepTest.p.then((obj)%20%3D%3E%20console.log(obj))%20%2F%2F%20pass%0D%0AdeepTest.p.then((obj)%20%3D%3E%20obj.q%20%3D%202))%20%2F%2F%20fail>)\r\n\r\n**Related Issues:**\r\nhttps://github.com/Microsoft/TypeScript/issues/27421\r\nhttps://github.com/Microsoft/TypeScript/issues/13923\r\nhttps://github.com/Microsoft/TypeScript/issues/26236\r\n\r\n","author":{"url":"https://github.com/masterkidan","@type":"Person","name":"masterkidan"},"datePublished":"2019-01-24T20:08:22Z","url":"https://github.com/microsoft/TypeScript/issues/29566"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:aa50c313-cce1-76bc-c63a-437b4b66b92c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 80BC:4279A:22CDA35:2ED67DA:6B01A340 |
| html-safe-nonce | 376c97b2c4875d25dc0b525b88c448c09eada10ed330a1a3e4fc63ff6232666b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEJDOjQyNzlBOjIyQ0RBMzU6MkVENjdEQTo2QjAxQTM0MCIsInZpc2l0b3JfaWQiOiI2OTY0Mjk0MDg5MzQ5MTEyNjQwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bddbcf24e24ec7ef450d573450ecafb93b89da435bb839329c586c6f6b02d649 |
| hovercard-subject-tag | issue:402875347 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/29566/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f53fef98dffbd3dfe0ac621c7ac3545f0512f77578c27e5f138c265a8a1bffb6/microsoft/TypeScript/issues/29566 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f53fef98dffbd3dfe0ac621c7ac3545f0512f77578c27e5f138c265a8a1bffb6/microsoft/TypeScript/issues/29566 |
| og:image:alt | TypeScript Version: 3.1.1+ Search Terms: DeepReadonly Code export type Primitive = string | number | boolean | undefined | null | Function | symbol; export type DeepReadonly |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | masterkidan |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width