Title: Getting recursive type errors with TS 4.3.2 when they don't happen with TS 4.2.4 · Issue #44281 · microsoft/TypeScript · GitHub
Open Graph Title: Getting recursive type errors with TS 4.3.2 when they don't happen with TS 4.2.4 · Issue #44281 · microsoft/TypeScript
X Title: Getting recursive type errors with TS 4.3.2 when they don't happen with TS 4.2.4 · Issue #44281 · microsoft/TypeScript
Description: Bug Report Given (this is just the smaller repro I could come up with, not real code): const p =
Open Graph Description: Bug Report Given (this is just the smaller repro I could come up with, not real code): const p =
X Description: Bug Report Given (this is just the smaller repro I could come up with, not real code): const p = <T>(fn: () => T): T => {return null as any} const Base = <T>(val: T): {new(): T} =...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/44281
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Getting recursive type errors with TS 4.3.2 when they don't happen with TS 4.2.4","articleBody":"# Bug Report\r\n\r\nGiven (this is just the smaller repro I could come up with, not real code):\r\n```ts\r\nconst p = \u003cT>(fn: () => T): T => {return null as any}\r\n\r\nconst Base = \u003cT>(val: T): {new(): T} => {\r\n return null as any;\r\n}\r\n\r\nclass C extends Base({\r\n x: p\u003cC[]>(() => [])\r\n}) { }\r\n```\r\n\r\nWith TS 4.3.2 it gives the errors:\r\n```\r\nType 'C' recursively references itself as a base type.ts(2310)\r\n'C' is referenced directly or indirectly in its own base expression.ts(2506)\r\n```\r\n\r\nwhere as there's no such error with TS 4.2.4\r\n\r\nIf the p function parameter is changed from `fn: () => T` to `fn: () => any` or ` x: p\u003cC[]>(() => [])` is changed to ` x: p\u003cC[]>(() => [] as any)` then it does not give that error anymore.\r\n\r\nReal impact:\r\n\r\nThis impacts a library that used to be able to do self-referenced models:\r\n```ts\r\nclass TreeNode extends Model({ children: prop\u003cTreeNode[]>(() => []), x: prop(0) }) {}\r\n```\r\nbut with the new version it is not possible anymore\r\n\r\nAlternative repro:\r\n\r\n```ts\r\nabstract class Base2 {\r\n abstract root() : Derived\r\n}\r\n\r\nclass Derived extends class extends Base2 {\r\n root() {\r\n return undefined as any\r\n }\r\n}\r\n{}\r\n```\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 4.2.4 and 4.3.2\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground Link](https://www.typescriptlang.org/play?jsx=0&ts=4.3.2&strict=true#code/LAKAxg9gdgzgLgAgA4ILwIDwBUB8AKAMygC4E8BKNHBLc0rKhAbwCcBTOAVxagSk4A2AhAEMYoqAE8AvqFCRYiAEJi2aTLjwA3EQPp1mUNgHcK9aYyagECdlx59BwsRMkBuULJDyBY8QGEENgAPODYoABNxFRg2PCsQBGDSJAx-AG0AXXwKRizyT0omBC9QAHoyiQg4AAs2FgQwVTkQEQAjeBYRMEQwXxho1QAmZmsbUQ64Lp7bCGrc0gAReoBLLTYIzxa+vwRlljWNoNDwqMb+8RCwyMHYkYSbFjm4XIfxu25eTki2AhWjCKicQiKRjLxeJjSIA)\r\n","author":{"url":"https://github.com/xaviergonz","@type":"Person","name":"xaviergonz"},"datePublished":"2021-05-26T23:02:56Z","url":"https://github.com/microsoft/TypeScript/issues/44281"}
| 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:591a91e7-a94d-cc27-1a7c-33769cb960e6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C67C:36A3E:F976F4:14DA3EE:6B01119C |
| html-safe-nonce | 8cefd0b35b1227cb9ced7363f33ef2601a471d3991ec9aa075dfd5dfe3912b97 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjdDOjM2QTNFOkY5NzZGNDoxNERBM0VFOjZCMDExMTlDIiwidmlzaXRvcl9pZCI6IjIwODIwMTUwMDgwMzU3NzA3ODAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f2c509ce5923d4c48f8bd8c98a0a5d81d16377fca9dc9de01006067b921a7a5a |
| hovercard-subject-tag | issue:903004125 |
| 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/44281/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f10d4bd1b350e73844f194993b3ae73fdbb1d570a81c75c1d4411d864837a719/microsoft/TypeScript/issues/44281 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f10d4bd1b350e73844f194993b3ae73fdbb1d570a81c75c1d4411d864837a719/microsoft/TypeScript/issues/44281 |
| og:image:alt | Bug Report Given (this is just the smaller repro I could come up with, not real code): const p = |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | xaviergonz |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width