Title: Inference regression (5.0.4 vs 4.9.5) with nullable enum function parameter · Issue #54005 · microsoft/TypeScript · GitHub
Open Graph Title: Inference regression (5.0.4 vs 4.9.5) with nullable enum function parameter · Issue #54005 · microsoft/TypeScript
X Title: Inference regression (5.0.4 vs 4.9.5) with nullable enum function parameter · Issue #54005 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms inference string null function parameter 🕗 Version & Regression Information This changed between versions 4.9.5 and 5.0.4 ⏯ Playground Link Playground link with relevant code 💻 Code enum Thing { a = 'a', b = 'b'...
Open Graph Description: Bug Report 🔎 Search Terms inference string null function parameter 🕗 Version & Regression Information This changed between versions 4.9.5 and 5.0.4 ⏯ Playground Link Playground link with relevant c...
X Description: Bug Report 🔎 Search Terms inference string null function parameter 🕗 Version & Regression Information This changed between versions 4.9.5 and 5.0.4 ⏯ Playground Link Playground link with releva...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/54005
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inference regression (5.0.4 vs 4.9.5) with nullable enum function parameter","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n--\u003e\r\n\r\n### 🔎 Search Terms\r\n\r\ninference string null function parameter \r\n\r\n### 🕗 Version \u0026 Regression Information\r\n\r\n- This changed between versions 4.9.5 and 5.0.4\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=5.0.4#code/KYOwrgtgBAKgFgSxAcygbygQygXigck3wBooAjXAskqAXwG4AoRgMzBAGMAXBAexCgsAFIyhioAJ2DIEAZy4TMPfgGUuSsLIDyAB2UhZALigrgAG2Ddd+2QB54SZAD5io8fwDCcTCmDGh8hpGsIgoUAA+UOBmZgCUuE5QAG68CAAmpAD0mVC2ALR5UABKwBC8ScBQXHCVAAaR0Wa1WCBpVTVQwBISvBJQyLzAslgA7pgAngB0jLHGKenobmKy5pZcQhjZuQVQAIJpbT6dAB46ZggcCFxV4zqVmBLIkKDXtQ4ozT5t1ZVdPX0DIajCbTcRgqC8PR8AzGKQyeSKfRqILWaGyVzg9wgLw+ZB+CHY7y+LI5ACiRSKWiKUCQyQArJMAAyTAAs5DA1xAvGutKSLMmAE5JnTjDBbpV8AF1FxNKLQqgGmAYvEcIl5ml8DThlzrphZLIEMgQJgyBYqrwbncCEIANbAcbGBGOFVq1Ia0HiWixJi0ZjAU69a5sTj6KArCzcWwAaXtMBOXFAaWGTpQTiEOh6OmCpgjXAACpm7DHxjAnLNkm7FmDqj0RlFgHXSd1ekJ8DUYrx8N7GL7GP6dIHLZUc2sC5Ci7H44nkwpHIk8GglgScb5-HaHVBizAXRX0kwwZCbAB+YwjqxQ-gTktOehQLb5QolMoVdp1I+fVqvzrNgGDYaYMYph7Jg+wDCRri4cUTFWc8bGjSd-QTVoZwkOdcCXLYPF4CAIBeTorhqPpeBYL8yHMXg63YaEoFwiAyIkYZeA5Fpvg6P5en6P9gSAsFIl2boJlsNB12MLdaCcJc+IE8Z4OvJggA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nenum Thing { a = 'a', b = 'b', };\r\n\r\nfunction f(\r\n registrationStatusOptions: SelectOptions\u003cThing\u003e,\r\n onChange: (status: Thing | null) =\u003e void, // \u003c-- Remove the `| null` and the error goes away.\r\n): void {\r\n select({ // \u003c-- Add an explicit type argument `Thing` and the error goes away.\r\n options: registrationStatusOptions,\r\n onChange: onChange, // ERROR in v5.0.4 but not in v4.9.5: Type '(status: Thing | null) =\u003e void' is not assignable to type '(key: string) =\u003e void'.\r\n });\r\n}\r\n\r\nexport function select\u003cKeyT extends string\u003e(props: SelectProps\u003cKeyT\u003e): void {\r\n throw new Error('hello');\r\n}\r\n\r\nexport type SelectProps\u003cKeyT extends string\u003e = {\r\n onChange: (key: KeyT) =\u003e void;\r\n options?: SelectOptions\u003cKeyT\u003e; // \u003c-- Remove the `?` and the error goes away.\r\n};\r\n\r\nexport type SelectOptions\u003cKeyT extends string\u003e =\r\n // Comment either of the below union members out and the error goes away.\r\n | Array\u003c{key: KeyT}\u003e\r\n | Array\u003cKeyT\u003e;\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\n1. Got a type error; see \"ERROR\" comment above. Looks like the type argument to `select(...)` is being inferred incorrectly.\r\n2. Minor perturbations of the code cause the error to go away; see other comments above.\r\n\r\nThis was extracted from some React UI code.\r\n\r\n### 🙂 Expected behavior\r\n\r\nTypeScript 4.9.5 infers the type argument I wanted. I was hoping TypeScript 5.0.4 would do the same.","author":{"url":"https://github.com/cakoose","@type":"Person","name":"cakoose"},"datePublished":"2023-04-25T07:58:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/54005/TypeScript/issues/54005"}
| 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:5a8e4f37-6efc-3a92-e001-dee175298145 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7D4:16E115:D7E2FE:12ADDCF:6A61A897 |
| html-safe-nonce | 6aab85e10515a1971a5732b42a6550e61fb2e38e8821e561c5be31674eb35414 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0Q0OjE2RTExNTpEN0UyRkU6MTJBRERDRjo2QTYxQTg5NyIsInZpc2l0b3JfaWQiOiI2MzY3NjA5NTQyOTI0MTUwOTM1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | af86db1f8d9385c8c671fa0f8e6bbf03cc9a853a35223d774811e39e3b451ae1 |
| hovercard-subject-tag | issue:1682640269 |
| 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/54005/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e26a068e60022f33fe7fdf26e4a3a6b023cea60f61c33c3fad32630120a136f2/microsoft/TypeScript/issues/54005 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e26a068e60022f33fe7fdf26e4a3a6b023cea60f61c33c3fad32630120a136f2/microsoft/TypeScript/issues/54005 |
| og:image:alt | Bug Report 🔎 Search Terms inference string null function parameter 🕗 Version & Regression Information This changed between versions 4.9.5 and 5.0.4 ⏯ Playground Link Playground link with relevant c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cakoose |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6f4633bcf01c1ad14b73fd07dd39ac31d61f3d3c2578ee08ec1792b7b351eeb9 |
| 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 | ac296ae7f21856f1f92adbad22f870b6fbb4b907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width