Title: extended diagnostic for non-nullable optional is wrong · Issue #46918 · angular/angular · GitHub
Open Graph Title: extended diagnostic for non-nullable optional is wrong · Issue #46918 · angular/angular
X Title: extended diagnostic for non-nullable optional is wrong · Issue #46918 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Having the case below produces the warning for optional chain operation. Because of ! it will always return a boolean to the input. Relates ...
Open Graph Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Having the case below produces the warning for optional chain operation. Because of ! it will always...
X Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Having the case below produces the warning for optional chain operation. Because of ! it will always...
Opengraph URL: https://github.com/angular/angular/issues/46918
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"extended diagnostic for non-nullable optional is wrong","articleBody":"### Which @angular/* package(s) are the source of the bug?\r\n\r\ncore\r\n\r\n### Is this a regression?\r\n\r\nNo\r\n\r\n### Description\r\n\r\nHaving the case below produces the warning for optional chain operation.\r\nBecause of `!` it will always return a boolean to the input.\r\nRelates to the new feature https://github.com/angular/angular/pull/46686 \r\nhttps://github.com/angular/angular/issues/44870\r\n\r\nAlso can we have a `angularCompilerOptions` to disable this warnings?\r\n\r\nFirst case:\r\n```ts\r\noptionalArrayElement: {a: 'value'}[] = [];\r\n```\r\n```html\r\n\u003cbutton [disabled]=\"!optionalArrayElement[0]?.a\">\u003c/button>\r\n```\r\n\r\nSecond case:\r\n```ts\r\nenum MapKeys {\r\n A,\r\n B\r\n}\r\n\r\n optionalMapElement: {[key: string]: {a: string}} = {[MapKeys.A] : {a: 'value'}};\r\n```\r\n\r\n```html\r\n\u003cbutton [disabled]=\"!optionalMapElement[MapKeys.B]?.a\">\u003c/button>\r\n```\r\n\r\n### Please provide a link to a minimal reproduction of the bug\r\n\r\nhttps://stackblitz.com/edit/angular-r3n3ec?file=src/app/app.component.ts\r\n\r\n### Please provide the exception or error you saw\r\n\r\n```true\r\nwarning NG8107: The left side of this optional chain operation does not include 'null' or 'undefined' in its type, therefore the '?.' operator can be replaced with the '.' operator.\r\n```\r\n\r\n\r\n### Please provide the environment you discovered this bug in (run `ng version`)\r\n\r\n```true\r\nAngular CLI: 14.1.0\r\nNode: 16.15.1\r\nPackage Manager: npm 8.13.2\r\nOS: win32 x64\r\n\r\nAngular: 14.1.0\r\n... animations, cli, common, compiler, compiler-cli, core, forms\r\n... platform-browser, platform-browser-dynamic, router\r\n... service-worker\r\n\r\nPackage Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect 0.1401.0\r\n@angular-devkit/build-angular 14.1.0\r\n@angular-devkit/core 14.1.0\r\n@angular-devkit/schematics 14.1.0\r\n@schematics/angular 14.1.0\r\nrxjs 7.5.6\r\ntypescript 4.7.4\r\n```\r\n\r\n\r\n### Anything else?\r\n\r\n_No response_","author":{"url":"https://github.com/tiberiuzuld","@type":"Person","name":"tiberiuzuld"},"datePublished":"2022-07-21T08:09:06Z","url":"https://github.com/angular/angular/issues/46918"}
| 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:77bd81f7-42b1-ab35-7c7f-31fbb06d4df8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B834:21BD98:3F7B9:4EEB4:6B00F3F2 |
| html-safe-nonce | 58ae005e07ed6ec402cd2325408812c0f1ce301f22665988cf2002dec770e859 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODM0OjIxQkQ5ODozRjdCOTo0RUVCNDo2QjAwRjNGMiIsInZpc2l0b3JfaWQiOiI3NDI3ODQ2NzY4OTYyNDA2MjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 93ac85b25ba31552f867fe3705d82c429bea3aabe0bd06aaabff189bb9615410 |
| hovercard-subject-tag | issue:1312853326 |
| 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/46918/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c71e8c49dde69123ad6854a812cecd713f604e84b297a96c002db2b086dab986/angular/angular/issues/46918 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c71e8c49dde69123ad6854a812cecd713f604e84b297a96c002db2b086dab986/angular/angular/issues/46918 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Having the case below produces the warning for optional chain operation. Because of ! it will always... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tiberiuzuld |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width