Title: String literal types in complex type expressions · Issue #7199 · microsoft/TypeScript · GitHub
Open Graph Title: String literal types in complex type expressions · Issue #7199 · microsoft/TypeScript
X Title: String literal types in complex type expressions · Issue #7199 · microsoft/TypeScript
Description: TypeScript Version: 1.8.2 Code interface Foo { ok:string; okToo: number; notOk: "o" | "k"; } interface Bar { bar: string; } interface FooBar extends Foo, Bar{ } function mix
Open Graph Description: TypeScript Version: 1.8.2 Code interface Foo { ok:string; okToo: number; notOk: "o" | "k"; } interface Bar { bar: string; } interface FooBar extends Foo, Bar{ } function mix
X Description: TypeScript Version: 1.8.2 Code interface Foo { ok:string; okToo: number; notOk: "o" | "k"; } interface Bar { bar: string; } interface FooBar extends Foo, Bar{ } function mix<...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7199
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"String literal types in complex type expressions","articleBody":"\u003c!--\nThank you for contributing to TypeScript! Please review this checklist\n before submitting your issue.\n[ ] Many common issues and suggestions are addressed in the FAQ\n https://github.com/Microsoft/TypeScript/wiki/FAQ\n[ ] Search for duplicates before logging new issues\n https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue\n[ ] Questions are best asked and answered at Stack Overflow\n http://stackoverflow.com/questions/tagged/typescript\n\nFor bug reports, please include the information below.\n__________________________________________________________ -->\n\n**TypeScript Version:** \n\n1.8.2\n\n**Code**\n\n``` ts\ninterface Foo {\n ok:string;\n okToo: number;\n notOk: \"o\" | \"k\";\n}\n\ninterface Bar {\n bar: string;\n}\n\ninterface FooBar extends Foo, Bar{\n}\n\nfunction mix\u003cT>(obj:T): T & Bar {\n (obj as any).bar=\"bar\";\n return obj as T & Bar;\n}\n\nvar fooBar:FooBar = mix({\n ok:\"ok\",\n okToo: 42,\n notOk:\"k\"\n});\n```\n\n**Expected behavior:**\n\nThe assignment to `fooBar` should be allowed. \n\n**Actual behavior:** \n\nI get the totally confusing error:\n\n```\nError:(20, 5) TS2322: Type '{ ok: string; notOk: string; } & Bar' is not assignable to type 'FooBar'.\n Type 'Bar' is not assignable to type 'FooBar'.\n Property 'ok' is missing in type 'Bar'.\n```\n\nThe confusing part is that it complains about the first property (`ok`) and not about `notOk`.\n\nLooking at the error message it seems that the string literal type `notOk:\"o\"|\"k\"` was converted to `notOk :string`.\n\nTherefore when I turn the string literal type to a string (`notOk:string`) everything is OK....\n\nHint: defining the string literal type as a type does _not_ solve the problem:\n\n``` ts\ntype NotOK = \"o\" | \"k\";\n\ninterface Foo {\n //...\n notOk: NotOK;\n}\n//...\n```\n","author":{"url":"https://github.com/scharf","@type":"Person","name":"scharf"},"datePublished":"2016-02-23T16:31:21Z","url":"https://github.com/microsoft/TypeScript/issues/7199"}
| 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:dc596b6d-b3c7-9f9c-bc14-60a55c09e537 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96A4:3E545B:4F0D4C:6A2884:6AFBF005 |
| html-safe-nonce | f0f9c74c9ea94419a409c5f5d55539e234e7e33d11dfa0d96cfc42865d8eb646 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkE0OjNFNTQ1Qjo0RjBENEM6NkEyODg0OjZBRkJGMDA1IiwidmlzaXRvcl9pZCI6IjQzMzU5MDQ1MjA4Nzg2ODIxMTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5654ea1c781a64a68ddcf8d1bc399cfbd7a967b919acea09efe1e0a4993a4329 |
| hovercard-subject-tag | issue:135787431 |
| 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/7199/issue_layout |
| twitter:image | https://opengraph.githubassets.com/030e4cb1c473bfbb405003884ddd463953ca5df4e06d72ceec49e61d8ca78f0d/microsoft/TypeScript/issues/7199 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/030e4cb1c473bfbb405003884ddd463953ca5df4e06d72ceec49e61d8ca78f0d/microsoft/TypeScript/issues/7199 |
| og:image:alt | TypeScript Version: 1.8.2 Code interface Foo { ok:string; okToo: number; notOk: "o" | "k"; } interface Bar { bar: string; } interface FooBar extends Foo, Bar{ } function mix |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | scharf |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| 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 | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width