Title: Having `noImplicitAny` Not Enabled Impacts Type Inference · Issue #47294 · microsoft/TypeScript · GitHub
Open Graph Title: Having `noImplicitAny` Not Enabled Impacts Type Inference · Issue #47294 · microsoft/TypeScript
X Title: Having `noImplicitAny` Not Enabled Impacts Type Inference · Issue #47294 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms array union types type inference noImplicitAny disabled 🕗 Version & Regression Information This changed between versions 4.2.3 and 4.3.5, as before 4.3.5, type inference for the 2nd case inferred any regardless ...
Open Graph Description: Bug Report 🔎 Search Terms array union types type inference noImplicitAny disabled 🕗 Version & Regression Information This changed between versions 4.2.3 and 4.3.5, as before 4.3.5, type inference f...
X Description: Bug Report 🔎 Search Terms array union types type inference noImplicitAny disabled 🕗 Version & Regression Information This changed between versions 4.2.3 and 4.3.5, as before 4.3.5, type inferen...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47294
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Having `noImplicitAny` Not Enabled Impacts Type Inference","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\narray union types type inference noImplicitAny disabled\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nThis changed between versions `4.2.3` and `4.3.5`, as before `4.3.5`, type inference for the 2nd case inferred `any` regardless of if `noImplicitAny` was enabled. After `4.3.5`, the expected inference happens when `noImplicitAny` is enabled, but behaves as it did before `4.3.5` when `noImplicitAny` is not enabled.\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?noImplicitAny=false&ts=4.5.4#code/PTAEAMEsBcFMFtygIYDsAmEDWsCeTkAnWUAIwHtoALUaXAB1k2QGdRYAPRgYzkwApwLaIUioA5qAA+oVAFd4pWIQIYI8xcvABKAFDdyqYSkKFkuAIwAuUAEFT5gDzDRE6bIVLCAPlABeUABtAF0Abn1DY3hkekZ0C38TM0sAOmj6fn4YBAAaUBxcbX9fQOz4PILgvV0QCDLVTHACgmIySho6OJQ2cDR8CKNoJPMAJht7ZOcRMXFfGQmnDS9fAJDwg0HQdLiRxKJkkbSYzLKKvCK-EtP8vCqgA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\n// `item` and `key` are both typed as expected (`string | number` and `number` respectively)\r\nconst array1: Array\u003cstring | number> = [];\r\nconst mapped1 = array1.map((item, key) => [item, key])\r\n\r\n// `item` and `key` are both typed as `any`\r\nconst array2: Array\u003cstring> | Array\u003cnumber> = [];\r\nconst mapped2 = array2.map((item, key) => [item, key])\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nWhen `noImplicitAny` is not enabled in the TS config, inferred types are impacted (inferred as `any` in the above case).\r\n\r\n### 🙂 Expected behavior\r\n\r\n`noImplicitAny` shouldn't impact inferred types, or if this is expected behaviour as having this option enabled allows for better heuristics to work, then I think having it documented that this settings isn't essentially just a \"lint rule\" might be a good idea.","author":{"url":"https://github.com/joealden","@type":"Person","name":"joealden"},"datePublished":"2022-01-03T15:23:20Z","url":"https://github.com/microsoft/TypeScript/issues/47294"}
| 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:78ade014-9940-d516-99b6-5b9d7419174e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 99B6:2978F1:9FB78A:CFAF60:6B00E3EE |
| html-safe-nonce | 70a9e1d6e36afc98816e96360c0bb3dbec9b33ff20c542386705f149e8ab08dc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OUI2OjI5NzhGMTo5RkI3OEE6Q0ZBRjYwOjZCMDBFM0VFIiwidmlzaXRvcl9pZCI6IjI5NzgwNTEyNDE2MDg3OTkyMTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ccbf3eb1b79245122c4be7220833f98b37213db2aa73ece490fa788e88fd8394 |
| hovercard-subject-tag | issue:1092599830 |
| 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/47294/issue_layout |
| twitter:image | https://opengraph.githubassets.com/89c814b3504090aa06ba45a74e5e015e39296b9b3e6e0770dab8b16c4f2a58dd/microsoft/TypeScript/issues/47294 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/89c814b3504090aa06ba45a74e5e015e39296b9b3e6e0770dab8b16c4f2a58dd/microsoft/TypeScript/issues/47294 |
| og:image:alt | Bug Report 🔎 Search Terms array union types type inference noImplicitAny disabled 🕗 Version & Regression Information This changed between versions 4.2.3 and 4.3.5, as before 4.3.5, type inference f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | joealden |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width