Title: Confusing error messages, invalid intellisense and no auto-complete with Tagged Unions that use string based Discriminators · Issue #10849 · microsoft/TypeScript · GitHub
Open Graph Title: Confusing error messages, invalid intellisense and no auto-complete with Tagged Unions that use string based Discriminators · Issue #10849 · microsoft/TypeScript
X Title: Confusing error messages, invalid intellisense and no auto-complete with Tagged Unions that use string based Discriminators · Issue #10849 · microsoft/TypeScript
Description: VsCode: 1.5.1 Typescript: 2.0.2 Window 10: 1607 I create a group of tagged unions that discriminate on the 'bundle' property which then causes a further discrimination on the values of the 'id' property: export module ModIcons_climacons ...
Open Graph Description: VsCode: 1.5.1 Typescript: 2.0.2 Window 10: 1607 I create a group of tagged unions that discriminate on the 'bundle' property which then causes a further discrimination on the values of the 'id' pro...
X Description: VsCode: 1.5.1 Typescript: 2.0.2 Window 10: 1607 I create a group of tagged unions that discriminate on the 'bundle' property which then causes a further discrimination on the values of the ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/10849
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Confusing error messages, invalid intellisense and no auto-complete with Tagged Unions that use string based Discriminators","articleBody":"\u003c!-- BUGS: Please use this template. -->\n\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\n\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\n- VsCode: **1.5.1**\n- Typescript: **2.0.2**\n- Window 10: **1607**\n\nI create a group of tagged unions that discriminate on the **'bundle'** property which then causes a further discrimination on the values of the **'id'** property:\n\n``` ts\nexport module ModIcons_climacons {\n export type DIcons_climacons = 'cloud' | 'cloud.sun' | 'cloud.moon' | 'rain' | 'rain.cloud' | 'rain.sun' | 'rain.cloud.sun' | 'rain.moon';\n\n export interface IIcons_climacons {\n bundle: \"climacons\";\n id: DIcons_climacons;\n }\n}\nexport module ModIcons_devicon {\n export type DIcons_devicon = 'postgresql-plain' | 'postgresql-plain-wordmark' | 'postgresql-plain.colore' \n | 'postgresql-plain-wordmark.colore' | 'nodejs-plain';\n\n export interface IIcons_devicon {\n bundle: \"devicon\";\n id: DIcons_devicon;\n }\n}\n\nexport module ModIcons_dripicons {\n export type DIcons_dripicons = 'align-center' | 'align-justify' | 'align-left' | 'align-right' | 'arrow-down' | 'arrow-left' | 'arrow-thin-down' | 'arrow-right' | 'arrow-thin-left' | 'arrow-thin-up' | 'arrow-up' | 'attachment' | 'arrow-thin-right' | 'code' | 'cloud' | 'chevron-right' | 'chevron-up';\n\n export interface IIcons_dripicons {\n bundle: \"dripicons\";\n id: DIcons_dripicons;\n }\n}\n\nexport module ModIcons_feather {\n export type DIcons_feather = 'eye' | 'paper-clip' | 'mail' | 'toggle' | 'layout' | 'link' | 'bell' | 'lock' | 'unlock' | 'ribbon' | 'image' | 'signal' | 'target' | 'clipboard' | 'clock' | 'watch' | 'air-play' | 'camera' | 'video' | 'disc' | 'printer' | 'monitor' | 'server' | 'cog' | 'heart' | 'paragraph' | 'align-justify' | 'align-left' | 'align-center' | 'align-right' | 'book' | 'layers' | 'stack' | 'stack-2' | 'paper' | 'paper-stack' | 'search' | 'zoom-in' | 'zoom-out' | 'reply' | 'circle-plus' | 'circle-minus' | 'circle-check' | 'circle-cross' | 'square-plus' | 'square-minus' | 'square-check' | 'square-cross' | 'microphone' | 'record' | 'skip-back' | 'rewind' | 'play' | 'pause' | 'stop' | 'fast-forward' | 'skip-forward' | 'shuffle' | 'repeat' | 'folder' | 'umbrella' | 'moon' | 'thermometer' | 'drop' | 'sun' | 'cloud' | 'cloud-upload' | 'cloud-download';\n\n export interface IIcons_feather {\n bundle: \"feather\";\n id: DIcons_feather;\n }\n}\n\n```\n\nI then create a tagged type union of the interfaces above with one additional interface of the same shape but that allows any value in the **'id'** property:\n\n``` ts\n\nexport interface IIconGlyphUnsafe {\n bundle: 'unsafe';\n id: string;\n}\n\nexport type UAll_Icons = iconsBase.IIconGlyphUnsafe | ModIcons_climacons.IIcons_climacons | ModIcons_devicon.IIcons_devicon \n| ModIcons_feather.IIcons_feather | ModIcons_dripicons.IIcons_dripicons;\n\n```\n# Case 1\n\nI consume the tagged union in a simple example like so:\n\n``` ts\nclass Hello {\n\n props: Icons.UAll_Icons;\n\n Test() {\n this.props = {\n };\n\n }\n}\n```\n\nHowever, I get the following error message:\n\n\u003cimg width=\"432\" alt=\"image1-dripicons-highlighted\" src=\"https://cloud.githubusercontent.com/assets/3457767/18414891/88fd9486-77a9-11e6-964b-c958268ca399.png\">\n\nThe message on line 2 is arbitrarily stating the type is not assignable to **'IIcons_dripicon'** which is 1 of the 5 tagged union types.\n\n**Expected behavior:** The message should state the type is not assignable to one of the five union types like \n\n> iconsBase.IIconGlyphUnsafe | ModIcons_climacons.IIcons_climacons | ModIcons_devicon.IIcons_devicon \n> | ModIcons_feather.IIcons_feather | ModIcons_dripicons.IIcons_dripicons\n# Case 2\n\nNow when I actually specify the **'bundle'** property which acts as the tag for this union with a value that is **not** part of the union's discriminator I get the following even further confusing message:\n\n\u003cimg width=\"565\" alt=\"image2-badtoken-dripicons-again\" src=\"https://cloud.githubusercontent.com/assets/3457767/18414892/9345bc8e-77a9-11e6-9648-c06b9dccd7da.png\">\n\nSo the messages on line 3 & 4 state that **'bundle'** property has the invalid value **'someBadToken'** and that it is not assignable to **'\"dripicons\"'**.\n\n**Expected behavior:** The message should state that the **'bundle'** property is not assignable to any of the following 5 possible values:\n\n> \"unsafe\" | \"climacons\" | \"devicon\" | \"dripicons\" | \"feather\"\n\n**Another Expected behavior:** The **bundle'** property should be highlighted at this stage with the not assignable message with all of the values listed above.\n\n**Another Expected behavior:** Auto-complete should be available with the list of appropriately scoped **'bundle'** property values.\n# Case 3\n\nWhen I begin to input the **'id'** property I get an intellisense tooltip that shows invalid values based on the value of the **'bundle'** property, see this screenshot:\n\n\u003cimg width=\"470\" alt=\"image4-bad-intellisense-for-id-property\" src=\"https://cloud.githubusercontent.com/assets/3457767/18414921/7837fedc-77ab-11e6-9dca-835fcfe65314.png\">\n\nWhat is being shown is a listing of all possible **'id'** values across the entire type union .\n\n**Expected behavior:** The **'id'** values should scope to the interface specified in **'bundle'**. In this case it should only show values from **'devicon'** interface.\n\n**Another Expected behavior:** Auto-complete should be available with the list of appropriately scoped **'id'** property values.\n# Source Code of Example\n\nThe source code for this issue is available here:\n\n[Typescript-Play.zip](https://github.com/Microsoft/TypeScript/files/465744/Typescript-Play.zip)\n\nI also just want to say that is a very powerful and welcome feature and has enabled some extremely powerful scenarios for our code.\n\nKeep up the great work!\n","author":{"url":"https://github.com/KavanShaban","@type":"Person","name":"KavanShaban"},"datePublished":"2016-09-11T03:25:37Z","url":"https://github.com/microsoft/TypeScript/issues/10849"}
| 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:6672f736-bce4-4977-2cd1-a82f97ef9f24 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CFFE:14700E:A1F9DA:CF4906:6B00F1A7 |
| html-safe-nonce | 5859543baed51aaf771c46e72bb33508e153c3dbec92353107d32ed6d9090cb1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRkZFOjE0NzAwRTpBMUY5REE6Q0Y0OTA2OjZCMDBGMUE3IiwidmlzaXRvcl9pZCI6IjEzNTQ4MzY1MjE4MDY1MjQ4MzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | cff3321565223a7f807819d6947ae9d415f82963412d60ed845c78143c8c673d |
| hovercard-subject-tag | issue:176217087 |
| 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/10849/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5f4dc637f603138862b47f7eb46e750144d173cd8a9c805a1e6cab97d5ad5b39/microsoft/TypeScript/issues/10849 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5f4dc637f603138862b47f7eb46e750144d173cd8a9c805a1e6cab97d5ad5b39/microsoft/TypeScript/issues/10849 |
| og:image:alt | VsCode: 1.5.1 Typescript: 2.0.2 Window 10: 1607 I create a group of tagged unions that discriminate on the 'bundle' property which then causes a further discrimination on the values of the 'id' pro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KavanShaban |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width