Title: Incorrectly inferred type for union types · Issue #43962 · microsoft/TypeScript · GitHub
Open Graph Title: Incorrectly inferred type for union types · Issue #43962 · microsoft/TypeScript
X Title: Incorrectly inferred type for union types · Issue #43962 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms infer, never, union types, error TS2345 🕗 Version & Regression Information This changed between versions 3.5.1 and all newer versions up to 4.3.0-beta. 3.5.1 doesn't throw such error, there is the error in 3.6.2...
Open Graph Description: Bug Report 🔎 Search Terms infer, never, union types, error TS2345 🕗 Version & Regression Information This changed between versions 3.5.1 and all newer versions up to 4.3.0-beta. 3.5.1 doesn't throw...
X Description: Bug Report 🔎 Search Terms infer, never, union types, error TS2345 🕗 Version & Regression Information This changed between versions 3.5.1 and all newer versions up to 4.3.0-beta. 3.5.1 doesn'...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/43962
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrectly inferred type for union types","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n### 🔎 Search Terms\r\n\r\n\u003c!--\r\n What search terms did you use when trying to find an existing bug report?\r\n List them here so people in the future can find this one more easily.\r\n-->\r\ninfer, never, union types, error TS2345\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n-->\r\n- This changed between versions 3.5.1 and all newer versions up to 4.3.0-beta. 3.5.1 doesn't throw such error, there is the error in 3.6.2\r\n \r\n### ⏯ Playground Link\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n-->\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?jsx=0&ts=3.6.3#code/C4TwDgpgBAKgFgSwHYHMA8MB8UC8UDeAUFCVAG4CGANgK4QBcsA3MaWApGgIIA0UAQnwDCmABStSpAPZgujAPJgMfLph4TJUGfwVLeAtRskyhutIKgiNASkbxk6ESwC+LUJCiK0AST7zseKLAiKh2IejemNa42PaoaP4shAAmEADGVBQATtAAZjRIacAIUkhQaTkUwBBx6FiiOQDONFTAdraw4RiYLKkZ2XkFRSVlALYUSjB8AEpiYFlSAFbpbVCilLQMsNE42NMdXlNQs73pmTlQ+YXFpVDAE92iSBAAHqvr1HTtMeRSCMkHSZ8LBJZDVLK5ChpaAAdSyE0gyTQADVsERJMkqhRGMiWJJ5jJGgB+RhSABGyyKLhSZwGlyGNzKCEacIRECR9XJi0YFCQIA6XKgzKgrLAiO6p36Fyuw1uBQA7vDJmIuXYoAAfEVK8VYDowJLuWHa9neJC5CBZHLJAAiWO6uFgUFe1SQyUaWrZSOQ5qyx2wROOUDsbnARs9prANGAKICax2sS6qKSfXOg2uIygFGSyQAyhBgMVUI0Y+IMVicRqPWL2TH1PiFmBGqSKStCB1ReKOyazRarbb7ijK12kajMD1CIQ0qVGsB6enSjCEMEYOAHN5Gs1oHgS5CilIsiBGMOI1HB5rhzGomEHDGfujSDlgDQsmVd8B9yBRNYAHTsSCicYwFEUQlwgUZ4ygBUlRA6pwOsPhAJgsCflA8CEImJDRh+KCMNQ6x8OpSdp1nYJmXXGBshQfNkU+LcoAARiSKckBnTMABIHRlRlF2XVdUHXTdgIg+8SGY1jSNQB0KggKoanCIJEEacjKOo2jrDxB982fMoJJQX8OAgUtNBIRDRExe4IKzXN80LFBGjMrE+HwTM+QABQbRh6KgZx8LrYyoFM8yKAgoL4KMUh7iA9YILIawbBcdSJwoNjvw2OgmCgAB6TKoEaOApBaZIoDJaApFyO5QzuRTlKyKjgBozYgA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\ntype Thing\u003cT> = {\r\n value: T;\r\n pipe\u003cA, B, C>(\r\n opA: Op\u003cT, A>,\r\n opB: Op\u003cA, B>,\r\n opC: Op\u003cB, C>\r\n ): Thing\u003cC>;\r\n};\r\ntype Op\u003cI, O> = (thing: Thing\u003cI>) => Thing\u003cO>;\r\n\r\ndeclare function createThing\u003cT>(result: T): Thing\u003cT>;\r\ndeclare function map\u003cT, R>(project: (value: T) => R): Op\u003cT, R>;\r\ndeclare function tap\u003cT>(next: (value: T) => void): Op\u003cT, T>;\r\n\r\ninterface Wrapped\u003cV> {\r\n data: V;\r\n props?: object;\r\n}\r\ndeclare function isWrapped\u003cT>(obj: any): obj is Wrapped\u003cT>;\r\ndeclare function unwrap\u003cT>(obj: T | Wrapped\u003cT>): T;\r\n\r\ntype WrappedInferredData\u003cT> = T extends Wrapped\u003cinfer R> ? R : T;\r\ntype WrappedInput\u003cV> = () => Thing\u003cV>;\r\n\r\ndeclare function addSettings\u003cV>(\r\n data: V | Wrapped\u003cV>,\r\n props: object\r\n): Wrapped\u003cWrappedInferredData\u003cV | Wrapped\u003cV>>>;\r\n\r\nconst functionWithTypingIssue = \u003cV>(factory: WrappedInput\u003cV | Wrapped\u003cV>>): Thing\u003cV> => {\r\n return factory().pipe(map((item) => unwrap(item)), map(item => item), map(item => unwrap(item)));\r\n}\r\n\r\nconst thisIsTargetValue = 1;\r\n\r\nconst a$ = functionWithTypingIssue(() => {\r\n const thing = createThing(thisIsTargetValue);\r\n return thing.pipe(\r\n map((data) => addSettings(data, { anyProp: 1 })),\r\n map((data) => data), // error here\r\n tap((v) => v)\r\n );\r\n});\r\n\r\na$.value; // should be of type thisIsTargetValue\r\n```\r\n```\r\nArgument of type 'Op\u003cWrapped\u003cnumber>, Wrapped\u003cnumber>>' is not assignable to parameter of type 'Op\u003cWrapped\u003cnumber>, Wrapped\u003cnever>>'.\r\n Type 'Wrapped\u003cnumber>' is not assignable to type 'Wrapped\u003cnever>'.\r\n Type 'number' is not assignable to type 'never'. \r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nType incorrectly infers from union type \r\n\r\n### 🙂 Expected behavior\r\n\r\nType should be resolved correctly. `typeof thisIsTargetValue === number` for this example\r\n","author":{"url":"https://github.com/RomanRolginSky","@type":"Person","name":"RomanRolginSky"},"datePublished":"2021-05-05T13:44:40Z","url":"https://github.com/microsoft/TypeScript/issues/43962"}
| 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:f9b1f0b8-1945-41f7-609e-ca4860b323ea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 91A2:3F8AB1:313DC57:3E956EA:6B01B4FA |
| html-safe-nonce | 616eddefe4258f779b50039113f22293ac0a0b92881d9486c6165a77bb9b0667 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUEyOjNGOEFCMTozMTNEQzU3OjNFOTU2RUE6NkIwMUI0RkEiLCJ2aXNpdG9yX2lkIjoiMjA2NDY1Nzk0NTY4MTA0ODgyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a7b83b55c8bcfdbdd6f96626b1368fb15881d20a4283aa2a96d7b219762f407e |
| hovercard-subject-tag | issue:876467790 |
| 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/43962/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d733f6912b35e22ca65e98d8faedadcc6ec67b409424c1e4e7cff10b9da5f334/microsoft/TypeScript/issues/43962 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d733f6912b35e22ca65e98d8faedadcc6ec67b409424c1e4e7cff10b9da5f334/microsoft/TypeScript/issues/43962 |
| og:image:alt | Bug Report 🔎 Search Terms infer, never, union types, error TS2345 🕗 Version & Regression Information This changed between versions 3.5.1 and all newer versions up to 4.3.0-beta. 3.5.1 doesn't throw... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RomanRolginSky |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width