Title: [Regression] Circular reference error when passing a class expression with non-primitive static properties to a generic function · Issue #59271 · microsoft/TypeScript · GitHub
Open Graph Title: [Regression] Circular reference error when passing a class expression with non-primitive static properties to a generic function · Issue #59271 · microsoft/TypeScript
X Title: [Regression] Circular reference error when passing a class expression with non-primitive static properties to a generic function · Issue #59271 · microsoft/TypeScript
Description: 🔎 Search Terms class expression static type 🕗 Version & Regression Information This changed between versions 4.0.5 and 4.1.5 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=4.1.5#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXzg2RlQElUAHZDA...
Open Graph Description: 🔎 Search Terms class expression static type 🕗 Version & Regression Information This changed between versions 4.0.5 and 4.1.5 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=4.1.5#code/CYU...
X Description: 🔎 Search Terms class expression static type 🕗 Version & Regression Information This changed between versions 4.0.5 and 4.1.5 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=4.1.5#code...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/59271
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Regression] Circular reference error when passing a class expression with non-primitive static properties to a generic function","articleBody":"### 🔎 Search Terms\r\n\r\nclass expression static type\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 4.0.5 and 4.1.5\r\n\r\n### ⏯ Playground Link\r\n\r\nhttps://www.typescriptlang.org/play/?ts=4.1.5#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXzg2RlQElUAHZDAHgBUA+ACi0uoC546BKTugbgBQgsHgDOGeFHgBeAiCIlyVDE0hQxY+AEF4Ab0EBICVGxgkOHLP0BfQTe5A\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ndeclare function returnInput\u003cT>(input: T): T;\r\n\r\nconst a = returnInput(class A {\r\n\tstatic foo = {}\r\n// ^?\r\n})\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\n`A.foo: any`\r\nError: 'foo' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)\r\n\r\nAnd also note that this bug only happens when the type of `foo` is **not** a primitive type.\r\n### 🙂 Expected behavior\r\n\r\n`A.foo: {}`, as it works in 4.0.5\r\n\r\n### Additional information about the issue\r\n\r\nTo define a React class component, it is a common practice to include its \"sub-components\" as private static properties. I also use a \"observer\" function to make the state change auto observed. So the real-world code may look like:\r\n```ts\r\nimport { observer } from 'mobx-react';\r\nimport { styled } from 'styled-components';\r\n\r\n@observer\r\nclass ListView extends React.Component {\r\n // render method here...\r\n private static readonly Item = observer(class Item extends React.Component {\r\n private static readonly Header = styled.h4` // \u003c- Cannot infer the type of Header\r\n // CSS style here...\r\n `;\r\n })\r\n}\r\n```\r\n\r\nA workaround is to use static block to initialize the static property but it's cumbersome:\r\n```ts\r\nconst a = returnInput(class A {\r\n\tstatic foo\r\n// ^? OK\r\n\tstatic { this.foo = {}; }\r\n})\r\n```","author":{"url":"https://github.com/whzx5byb","@type":"Person","name":"whzx5byb"},"datePublished":"2024-07-14T19:39:27Z","url":"https://github.com/microsoft/TypeScript/issues/59271"}
| 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:e0680298-896b-94da-601e-7f4cf225d330 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96A2:2454CC:FD0F5F:141EED1:6B0112B4 |
| html-safe-nonce | b1b14557838bef57a9628d443c10517f0b29ff0d5ce86585276aaa10d9b71357 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkEyOjI0NTRDQzpGRDBGNUY6MTQxRUVEMTo2QjAxMTJCNCIsInZpc2l0b3JfaWQiOiI3NDUyNTEwMTg1ODkwODQ1MzY0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 11ae4779c5dd8fe0cd9666140608a928ec4929eace37048f98cb5820ff24fee8 |
| hovercard-subject-tag | issue:2407570913 |
| 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/59271/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6096b923428fdcb8b36197e552c6e1b539a89fb8c7c35cad13a92e7e20d0c2aa/microsoft/TypeScript/issues/59271 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6096b923428fdcb8b36197e552c6e1b539a89fb8c7c35cad13a92e7e20d0c2aa/microsoft/TypeScript/issues/59271 |
| og:image:alt | 🔎 Search Terms class expression static type 🕗 Version & Regression Information This changed between versions 4.0.5 and 4.1.5 ⏯ Playground Link https://www.typescriptlang.org/play/?ts=4.1.5#code/CYU... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | whzx5byb |
| 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