Title: Using ?. in template does not narrow type · Issue #47077 · angular/angular · GitHub
Open Graph Title: Using ?. in template does not narrow type · Issue #47077 · angular/angular
X Title: Using ?. in template does not narrow type · Issue #47077 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? compiler, core, language-service Is this a regression? No Description with strict mode on for TypeScript "compilerOptions": { "strict": true, ... export type AccessibleValue
Open Graph Description: Which @angular/* package(s) are the source of the bug? compiler, core, language-service Is this a regression? No Description with strict mode on for TypeScript "compilerOptions": { "strict": true, ...
X Description: Which @angular/* package(s) are the source of the bug? compiler, core, language-service Is this a regression? No Description with strict mode on for TypeScript "compilerOptions": { "...
Opengraph URL: https://github.com/angular/angular/issues/47077
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using ?. in template does not narrow type","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncompiler, core, language-service\n\n### Is this a regression?\n\nNo\n\n### Description\n\nwith strict mode on for TypeScript\r\n\r\n```\r\n \"compilerOptions\": {\r\n \"strict\": true,\r\n ...\r\n``` \r\n\r\n```\r\nexport type AccessibleValue\u003cT> =\r\n | { isAccessible: true; value: T }\r\n | {\r\n isAccessible: false;\r\n value: null;\r\n };\r\n```\r\nevaluates to string correctly in typescript\r\n```\r\n if (this.testValue.accessible?.isAccessible) {\r\n this.stringOnlyToTest = this.testValue.accessible.value; \r\n }\r\n```\r\nbut in the template, it throws \r\n```\r\nArgument of type 'string | null' is not assignable to parameter of type 'string'.\r\nType 'null' is not assignable to type 'string'.\r\n```\r\n```\r\n\u003cp *ngIf=\"testValue.accessible?.isAccessible\">\r\n{{ testValue.accessible.value | stringOnlyPipe }} \u003cspan>\u003c/span> \r\n\u003c/p>\r\n```\n\n### Please provide a link to a minimal reproduction of the bug\n\nhttps://stackblitz.com/edit/angular-ivy-gpknqn?file=src/app/app.component.ts\n\n### Please provide the exception or error you saw\n\n```true\nArgument of type 'string | null' is not assignable to parameter of type 'string'.\r\nType 'null' is not assignable to type 'string'.\n```\n\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular CLI: 14.1.1\r\nNode: 14.16.0\r\nPackage Manager: npm 6.14.11\r\nOS: win32 x64\r\n\r\nAngular: 14.1.1\r\n... animations, cli, common, compiler, compiler-cli, core, forms\r\n... platform-browser, platform-browser-dynamic, router\r\n\r\nPackage Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect 0.1401.1\r\n@angular-devkit/build-angular 14.1.1\r\n@angular-devkit/core 14.1.1\r\n@angular-devkit/schematics 14.1.1\r\n@schematics/angular 14.1.1\r\nrxjs 7.5.6\r\ntypescript 4.6.4\n```\n\n\n### Anything else?\n\nI'm pretty sure there are actually more problems with regards to `?.` operator in templates and will try to provide as many as I am able to find while fixing the project I work on currently","author":{"url":"https://github.com/kbrilla","@type":"Person","name":"kbrilla"},"datePublished":"2022-08-08T11:19:03Z","url":"https://github.com/angular/angular/issues/47077"}
| 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:39c4c41f-a6e4-e609-c74b-2ac578fcc5a6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB74:172B92:171466A:1ECAE47:6B01414A |
| html-safe-nonce | 02b79767ff26fe71a75efd1843948c93d4cb268858a8379d6a25843f0b28f2d1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjc0OjE3MkI5MjoxNzE0NjZBOjFFQ0FFNDc6NkIwMTQxNEEiLCJ2aXNpdG9yX2lkIjoiMjYwMDM5MjcxODU3MjE0MjkyMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d15fa99b848492d1c50f6be1b14876a324defc3a083ba49352b462fb7e679084 |
| hovercard-subject-tag | issue:1331721130 |
| 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/47077/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b4f657468953a33568cd478c0b18d773479feb2a730b9e40212c543441ec5400/angular/angular/issues/47077 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b4f657468953a33568cd478c0b18d773479feb2a730b9e40212c543441ec5400/angular/angular/issues/47077 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? compiler, core, language-service Is this a regression? No Description with strict mode on for TypeScript "compilerOptions": { "strict": true, ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kbrilla |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width