Title: Incorrect circularity detection · Issue #33191 · microsoft/TypeScript · GitHub
Open Graph Title: Incorrect circularity detection · Issue #33191 · microsoft/TypeScript
X Title: Incorrect circularity detection · Issue #33191 · microsoft/TypeScript
Description: TypeScript Version: 3.6.2 Search Terms: 7022 directly or indirectly in its own initializer Code function extent(nums: number[]) { let result: [number, number] | null = null; for (const num of nums) { if (!result) { result = [num, num]; }...
Open Graph Description: TypeScript Version: 3.6.2 Search Terms: 7022 directly or indirectly in its own initializer Code function extent(nums: number[]) { let result: [number, number] | null = null; for (const num of nums)...
X Description: TypeScript Version: 3.6.2 Search Terms: 7022 directly or indirectly in its own initializer Code function extent(nums: number[]) { let result: [number, number] | null = null; for (const num of nums)...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/33191
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect circularity detection","articleBody":"**TypeScript Version:** 3.6.2\r\n\r\n**Search Terms:**\r\n\r\n- 7022\r\n- directly or indirectly in its own initializer\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction extent(nums: number[]) {\r\n let result: [number, number] | null = null;\r\n for (const num of nums) {\r\n if (!result) {\r\n result = [num, num];\r\n } else {\r\n const [oldMin, oldMax] = result;\r\n result = [Math.min(num, oldMin), Math.max(num, oldMax)];\r\n }\r\n }\r\n return result;\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nNo error.\r\n\r\n**Actual behavior:**\r\n\r\n```\r\n'oldMin' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)\r\n'oldMax' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)\r\n```\r\n\r\nI'm really struggling to see where the circularity comes in. The type of `result` is shown as `[number, number]` in that branch, so I'd assume destructuring it would result in two `number` types.\r\n\r\nRemoving the destructuring and using array accesses is equivalent but produces no error:\r\n\r\n```ts\r\nfunction extent(nums: number[]) {\r\n let result: [number, number] | null = null;\r\n for (const num of nums) {\r\n if (!result) {\r\n result = [num, num];\r\n } else {\r\n result = [Math.min(num, result[0]), Math.max(num, result[1])]; // ok\r\n }\r\n }\r\n return result;\r\n}\r\n```\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior --> [link][1]\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n\r\n- https://github.com/microsoft/TypeScript/issues/32950\r\n\r\n[1]: https://typescript-play.js.org/#code/GYVwdgxgLglg9mABAUwB5WWKAKMIC2AzgFyJ74BGyATgNoC6AlIgN4BQiiANslItckIguUUrXJVqAGjIFJ9RAB9ZXLogC8KrgG4OiYHGqJsEBIT7lEcYLKLN2nTjBvYAhAKEj7ex-0HC+TXECGXJ6XV8AXxQuQmRWH0dTMHNEWjguABMAWRgwGQycgENUBU0PAIjfP09AtOyiqAALADp8PNwQqyzcsEYZBua2ks78Ap6SxnDEyL1ZzgEoEGokCpFdWaA","author":{"url":"https://github.com/danvk","@type":"Person","name":"danvk"},"datePublished":"2019-09-02T14:46:05Z","url":"https://github.com/microsoft/TypeScript/issues/33191"}
| 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:f6eadbb4-4fb4-3ea3-170d-d0c6956020df |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A5AC:1EC9BC:C37322:FA3779:6B00FF0C |
| html-safe-nonce | 0ba62520d08e6a656811ceb0e63b55b7fefebf58aab234cd98d3870ec0e088a2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNUFDOjFFQzlCQzpDMzczMjI6RkEzNzc5OjZCMDBGRjBDIiwidmlzaXRvcl9pZCI6IjMxMjE2NjkwMjA5MzIxNzc2NzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7f70c46215f8f0747ec1930e0e1b35a9271cbc230f1bcf9d0464684bdde383bb |
| hovercard-subject-tag | issue:488224915 |
| 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/33191/issue_layout |
| twitter:image | https://opengraph.githubassets.com/20204376c465b62a8b20c1c65a893b893761a5d690f8de0397622f3a0a771d2a/microsoft/TypeScript/issues/33191 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/20204376c465b62a8b20c1c65a893b893761a5d690f8de0397622f3a0a771d2a/microsoft/TypeScript/issues/33191 |
| og:image:alt | TypeScript Version: 3.6.2 Search Terms: 7022 directly or indirectly in its own initializer Code function extent(nums: number[]) { let result: [number, number] | null = null; for (const num of nums)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | danvk |
| 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