Title: Language Service: More forgiving support of union types in templates · Issue #17953 · angular/angular · GitHub
Open Graph Title: Language Service: More forgiving support of union types in templates · Issue #17953 · angular/angular
X Title: Language Service: More forgiving support of union types in templates · Issue #17953 · angular/angular
Description: I'm submitting a ... [ ] Regression (behavior that used to work and stopped working in a new release) [] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request => Please do not submit support request here, ...
Open Graph Description: I'm submitting a ... [ ] Regression (behavior that used to work and stopped working in a new release) [] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request => Ple...
X Description: I'm submitting a ... [ ] Regression (behavior that used to work and stopped working in a new release) [] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request =&...
Opengraph URL: https://github.com/angular/angular/issues/17953
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Language Service: More forgiving support of union types in templates","articleBody":"## I'm submitting a ...\r\n\u003cpre>\u003ccode>\r\n[ ] Regression (behavior that used to work and stopped working in a new release)\r\n[] Bug report \u003c!-- Please search github for a similar issue or PR before submitting -->\r\n[x] Feature request\r\n[ ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n\u003c/code>\u003c/pre>\r\n\r\n## Current behavior\r\nWhen I have a variable in my component with a union type, the language service will complain if I reference any properties which are not common to all members of the union type. Sometimes it may be valid to try to reference these non-shared properties, e.g.:\r\n\r\n```TypeScript\r\nimport { Component } from '@angular/core';\r\n\r\nexport interface Line {\r\n length: number;\r\n dimensions: number;\r\n}\r\n\r\nexport interface Plane {\r\n area: number;\r\n dimensions: number;\r\n}\r\n\r\n@Component({\r\n selector: 'app-root',\r\n template: ` {{ shape.length || shape.area }}\r\n {{ shape.dimensions }}\r\n\r\n \u003cdiv *ngFor=\"let item of collection\">\r\n {{ item.length || item.area }}\r\n {{ item.dimensions }}\r\n \u003c/div>\r\n`})\r\nexport class AppComponent {\r\n collection: Array\u003cLine|Plane> = [];\r\n shape: Line|Plane;\r\n}\r\n```\r\nHere is a screenshot of the output from VS Code using the language service plugin:\r\n\r\n\r\n\r\n## Expected behavior\r\nI would expect to be able to use the above construction without errors.\r\n\r\n## Minimal reproduction of the problem with instructions\r\n1. Create a new angular CLI project with `@angular/cli 1.2.0`\r\n2. Replace the contents of app.component.ts with the code above\r\n3. View in VS Code with the language service plugin enabled. My version of the plugin uses `@angular/language-service@4.1.0-beta`\r\n\r\n## What is the motivation / use case for changing the behavior?\r\nThe example above illustrates a simple uses case. In my app I have a situation where I have a generic component which can be passed different types of object, and uses the `||` operator to display the first truthy value.\r\n\r\n\r\n## Please tell us about your environment\r\n\r\n\u003cpre>\u003ccode> \r\nFor Tooling issues:\r\n- Node version: 7.7.1\r\n- Platform: Windows 10\r\n- VS Code 1.13.1\r\n- @angular/language-service@4.1.0-beta\r\n- Typescript@2.1.5\r\n\u003c/code>\u003c/pre>\r\n","author":{"url":"https://github.com/michaelbromley","@type":"Person","name":"michaelbromley"},"datePublished":"2017-07-06T10:02:02Z","url":"https://github.com/angular/angular/issues/17953"}
| 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:4d264471-6bac-89cd-df74-2dd2c8f348da |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3AA:2270F4:32C580C:435C7EC:6B01EE66 |
| html-safe-nonce | 97ffe251012533a0722f1ba73c654884b48569bd4890b2911ec38450866f1684 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0FBOjIyNzBGNDozMkM1ODBDOjQzNUM3RUM6NkIwMUVFNjYiLCJ2aXNpdG9yX2lkIjoiMzM0OTczNDc2MDc2MjE3NTA3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 900d4ad09fd0d24e3c396d11d9f85124995393c8b6814f1cf8867a2eee8bea4a |
| hovercard-subject-tag | issue:240905844 |
| 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/angular/angular/17953/issue_layout |
| twitter:image | https://opengraph.githubassets.com/29399dc576873420be3703290a501191259c325cbb4f252204f2ad210dfb1197/angular/angular/issues/17953 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/29399dc576873420be3703290a501191259c325cbb4f252204f2ad210dfb1197/angular/angular/issues/17953 |
| og:image:alt | I'm submitting a ... [ ] Regression (behavior that used to work and stopped working in a new release) [] Bug report [x] Feature request [ ] Documentation issue or request [ ] Support request => Ple... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | michaelbromley |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width