Title: Complex Union type with generics could not assign return type · Issue #43749 · microsoft/TypeScript · GitHub
Open Graph Title: Complex Union type with generics could not assign return type · Issue #43749 · microsoft/TypeScript
X Title: Complex Union type with generics could not assign return type · Issue #43749 · microsoft/TypeScript
Description: Bug Report I don't know which is the correct behavior... I would appreciate it if you could change the title of the issue. 🔎 Search Terms generic return type union extend maybe related: #43425 🕗 Version & Regression Information This chan...
Open Graph Description: Bug Report I don't know which is the correct behavior... I would appreciate it if you could change the title of the issue. 🔎 Search Terms generic return type union extend maybe related: #43425 🕗 Ve...
X Description: Bug Report I don't know which is the correct behavior... I would appreciate it if you could change the title of the issue. 🔎 Search Terms generic return type union extend maybe related: #43425 ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/43749
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Complex Union type with generics could not assign return type","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\nI don't know which is the correct behavior...\r\nI would appreciate it if you could change the title of the issue.\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\n\r\ngeneric return type union extend\r\n\r\nmaybe related: https://github.com/microsoft/TypeScript/issues/43425\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 4.3.0-dev.20210315 and 4.3.0-dev.20210323\r\n- I was unable to test this on prior versions (before v3.5.1) because `Omit` was not implemented.\r\n\r\n### ⏯ Playground Link\r\n\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?ts=next#code/C4TwDgpgBA4glgNwgOwJIBMAq5oF4rICuAtgEYQBOA3ALABQokUAysBXMgOYCGpANhAzYm+ImUq069DsEoAzbgGNoAWRDDoAb3pRdUTohQYAXLENosOSXqgBnNhx79B6U63ZdeAoVfoBfenpGaEwAewAFClDIClAAOUI+PgAeTAAaKABpKAgAD1lkdFsoAGsIEFC5KEwAPih8TSgAbXCoDlLyyuqAXVNWvIKirKgAfgJEvihTTBbuqD9JYKgAQXQsYjAMDFSM7IGUIbKKqtr66oiomPiJnay6gDIoRuANkzsHLnnJIJwWD6cBBozgB5YhwYDJNQaDIAcnsHgBLhhDyeOj08McXhcpgxXEkCygAHpCU99OY3vAkBZoe8EVi3rjOPMfkw4qFkJSjOgAOrggAWmFe6DOq3Wm3Q2zRuncmOc0KlUBhBipGBh9BqVCJJMayq5piISQyjPprlpjgyL3FOP+zKkdEU7PsUFkTvwyQVmBy+QOxRlnjlvwAPlA2RzyTz+YLxeqABQKhDTegASlMMdB4NucP+JuRSagj0axucbz9iJ8TD89TqMe0dBsADpGwg0gqi95TQlxBR62BuBRbIJkMAYwh622XBkAIwABiTLbofiTVCAA)\r\n[worked 4.3.0-dev.20210315](https://www.typescriptlang.org/play?ts=4.3.0-dev.20210315&ssl=1&ssc=1&pln=2&pc=1#code/C4TwDgpgBA4glgNwgOwJIBMAq5oF4rICuAtgEYQBOA3ALABQokUAysBXMgOYCGpANhAzYm+ImUq069DsEoAzbgGNoAWRDDoAb3pRdUTohQYAXLENosOSXqgBnNhx79B6U63ZdeAoVfoBfenpGaEwAewAFClDIClAAOUI+PgAeTAAaKABpKAgAD1lkdFsoAGsIEFC5KEwAPih8TSgAbXCoDlLyyuqAXVNWvIKirKgAfgJEvihTTBbuqD9JYKgAQXQsYjAMDFSM7IGUIbKKqtr66oiomPiJnay6gDIoRuANkzsHLnnJIJwWD6cBBozgB5YhwYDJNQaDIAcnsHgBLhhDyeOj08McXhcpgxXEkCygAHpCU99OY3vAkBZoe8EVi3rjOPMfkw4qFkJSjOgAOrggAWmFe6DOq3Wm3Q2zRuncmOc0KlUBhBipGBh9BqVCJJMayq5piISQyjPprlpjgyL3FOP+zKkdEU7PsUFkTvwyQVmBy+QOxRlnjlvwAPlA2RzyTz+YLxeqABQKhDTegASlMMdB4NucP+JuRSagj0axucbz9iJ8TD89TqMe0dBsADpGwg0gqi95TQlxBR62BuBRbIJkMAYwh622XBkAIwABiTLbofiTVCAA)\r\n[not worked 4.3.0-dev.20210323](https://www.typescriptlang.org/play?ts=4.3.0-dev.20210323#code/C4TwDgpgBA4glgNwgOwJIBMAq5oF4rICuAtgEYQBOA3ALABQokUAysBXMgOYCGpANhAzYm+ImUq069DsEoAzbgGNoAWRDDoAb3pRdUTohQYAXLENosOSXqgBnNhx79B6U63ZdeAoVfoBfenpGaEwAewAFClDIClAAOUI+PgAeTAAaKABpKAgAD1lkdFsoAGsIEFC5KEwAPih8TSgAbXCoDlLyyuqAXVNWvIKirKgAfgJEvihTTBbuqD9JYKgAQXQsYjAMDFSM7IGUIbKKqtr66oiomPiJnay6gDIoRuANkzsHLnnJIJwWD6cBBozgB5YhwYDJNQaDIAcnsHgBLhhDyeOj08McXhcpgxXEkCygAHpCU99OY3vAkBZoe8EVi3rjOPMfkw4qFkJSjOgAOrggAWmFe6DOq3Wm3Q2zRuncmOc0KlUBhBipGBh9BqVCJJMayq5piISQyjPprlpjgyL3FOP+zKkdEU7PsUFkTvwyQVmBy+QOxRlnjlvwAPlA2RzyTz+YLxeqABQKhDTegASlMMdB4NucP+JuRSagj0axucbz9iJ8TD89TqMe0dBsADpGwg0gqi95TQlxBR62BuBRbIJkMAYwh622XBkAIwABiTLbofiTVCAA)\r\n\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\ntype GivenIdType = number;\r\ntype StringableIdType = number;\r\n\r\ninterface MyType {\r\n givenId: GivenIdType;\r\n stringableId: StringableIdType;\r\n}\r\n\r\ntype ToPropertyNull\u003cT, K extends keyof T> = { [P in keyof T]: P extends K ? null : T[P] };\r\ntype AddTmpIdId\u003cT, K extends keyof T> = ToPropertyNull\u003cT, K> & { tmpId: string };\r\n\r\ntype StringableType = Omit\u003cMyType, 'stringableId'> & {\r\n stringableId: string;\r\n}; // { givenId: GivenIdType, stringableId: string }\r\ntype NonGivenIdWithTmpId = AddTmpIdId\u003c\r\n StringableType,\r\n 'givenId'\r\n>; // { givenId: null, stringableId: string, tmpId: string }\r\n\r\nconst test = \u003c\r\n T extends StringableType | NonGivenIdWithTmpId\r\n>(\r\n v: T\r\n): (Omit\u003cT, 'stringableId'>) & { stringableId: StringableIdType } => ({\r\n ...v,\r\n stringableId: Number.parseInt(v.stringableId, 10),\r\n});\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\n\u003c!-- What happened, and why it was wrong -->\r\n\r\ncannot assign function argument to return type\r\n\r\n> Type '{ stringableId: number; givenId: number; } | { stringableId: number; givenId: null; tmpId: string; }' is not assignable to type 'Omit\u003cT, \"stringableId\"> & { stringableId: number; }'.\r\n\r\n### 🙂 Expected behavior\r\n\r\n\u003c!-- What you expected to happen instead, and why -->\r\n\r\nUnion type function arguments given by generics can be used as part of the return type\r\n","author":{"url":"https://github.com/yamachu","@type":"Person","name":"yamachu"},"datePublished":"2021-04-20T13:53:20Z","url":"https://github.com/microsoft/TypeScript/issues/43749"}
| 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:c5a21cc6-c5b1-6fd9-0413-22fbf4c1aca3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A02A:41678:4E1671:66DDCC:6B0176F6 |
| html-safe-nonce | 9b327463c47ea4b1af89f445ce88c2e4918fb5b0e466baa32d34d46cd144d863 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDJBOjQxNjc4OjRFMTY3MTo2NkREQ0M6NkIwMTc2RjYiLCJ2aXNpdG9yX2lkIjoiNjQ4MzkzNjMzOTg1MDAwMDExOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1e7d1b6fe21f6571a7c5668f5806b2028fd581cd356fac0a31f3a01a03020ea9 |
| hovercard-subject-tag | issue:862843143 |
| 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/43749/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b4e057bd930fcdd37babe6176019692a85903366f422060140f8669d9a247b3b/microsoft/TypeScript/issues/43749 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b4e057bd930fcdd37babe6176019692a85903366f422060140f8669d9a247b3b/microsoft/TypeScript/issues/43749 |
| og:image:alt | Bug Report I don't know which is the correct behavior... I would appreciate it if you could change the title of the issue. 🔎 Search Terms generic return type union extend maybe related: #43425 🕗 Ve... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yamachu |
| 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