Title: Ivy compiler incorrectly allows undefined to be passed to any component input even without explicit undefined in input type when strictNullChecks is on · Issue #32690 · angular/angular · GitHub
Open Graph Title: Ivy compiler incorrectly allows undefined to be passed to any component input even without explicit undefined in input type when strictNullChecks is on · Issue #32690 · angular/angular
X Title: Ivy compiler incorrectly allows undefined to be passed to any component input even without explicit undefined in input type when strictNullChecks is on · Issue #32690 · angular/angular
Description: 🐞 bug report Affected Package Not exactly sure, but probably: @angular/compiler @angular/compiler-cli Is this a regression? No, from my experience, the old compiler didn't enforce strictNullChecks in templates at all, so this is new to I...
Open Graph Description: 🐞 bug report Affected Package Not exactly sure, but probably: @angular/compiler @angular/compiler-cli Is this a regression? No, from my experience, the old compiler didn't enforce strictNullChecks ...
X Description: 🐞 bug report Affected Package Not exactly sure, but probably: @angular/compiler @angular/compiler-cli Is this a regression? No, from my experience, the old compiler didn't enforce strictNullChe...
Opengraph URL: https://github.com/angular/angular/issues/32690
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Ivy compiler incorrectly allows undefined to be passed to any component input even without explicit undefined in input type when strictNullChecks is on","articleBody":"\u003c!--🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅\r\n\r\nOh hi there! 😄\r\n\r\nTo expedite issue processing please search open and closed issues before submitting a new one.\r\nExisting issues often contain information about workarounds, resolution, or progress updates.\r\n\r\n🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅-->\r\n\r\n\r\n# 🐞 bug report\r\n\r\n### Affected Package\r\n\u003c!-- Can you pin-point one or more @angular/* packages as the source of the bug? -->\r\n\r\nNot exactly sure, but probably:\r\n@angular/compiler\r\n@angular/compiler-cli\r\n\r\n### Is this a regression?\r\n\r\n\u003c!-- Did this behavior use to work in the previous version? --> \r\n\r\nNo, from my experience, the old compiler didn't enforce strictNullChecks in templates at all, so this is new to Ivy.\r\n\r\n### Description\r\n\r\nWith `strictNullChecks` turned _on_, if you have a component input with a certain type that does _not_ explicitly include `undefined`, the Ivy compiler _does not complain_ if you pass `undefined` to that input from another component. This defeats a lot of the purpose of using `strictNullChecks`. (Note that it does complain about passing `null` if `null` isn't explicitly in the type, so I know `strictNullChecks` is enabled properly.)\r\n\r\nI believe this is due to the use of `Partial\u003cPick\u003c...>>` in the type check block for the template as described here: https://blog.angularindepth.com/type-checking-templates-in-angular-viewengine-and-ivy-77f8536359f5\r\n\r\n`Partial\u003c...>` causes each property to be made optional, which in effect adds `undefined` to the type of each property as well, as described in the TypeScript docs: `Optional parameters and properties automatically have undefined added to their types, even when their type annotations don’t specifically include undefined.`. (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#optional-parameters-and-properties)\r\n\r\nSo, what seems to be happening is the Ivy compiler is adding `undefined` to the type of every input when considering the bindings, which means it will never complain about passing `undefined` to the input of any component. That really makes `strictNullChecks` a lot less useful.\r\n\r\nPlease understand that although nobody in practice would probably pass a hardcoded `undefined` to a component input, this is an actual problem any time you use `undefined` to represent the absence of a value being passed to a component. In my case, I have a store I subscribe to using the `async` pipe, and then some of the state gets passed into child components from there. Various properties on my state have types like `SomeModel | undefined`. `undefined` could mean the model is not yet loaded, for example. Although some people may use `null` instead, there seems to be a significant group that prefers to use `undefined` in all cases. Wherever you fall on that debate, my point is that this definitely comes into play in real projects, and in fact I'm having the issue after switching to Ivy in my own project. I can't have a lot of confidence in what I'm passing to my components' inputs if `undefined` is always allowed by the compiler regardless of the actual type of the inputs.\r\n\r\n## 🔬 Minimal Reproduction\r\n\u003c!--\r\nPlease create and share minimal reproduction of the issue starting with this template: https://stackblitz.com/fork/angular-issue-repro2\r\n-->\r\n\r\n\u003c!--\r\nIf StackBlitz is not suitable for reproduction of your issue, please create a minimal GitHub repository with the reproduction of the issue.\r\nA good way to make a minimal reproduction is to create a new app via `ng new repro-app` and add the minimum possible code to show the problem. \r\nShare the link to the repo below along with step-by-step instructions to reproduce the problem, as well as expected and actual behavior.\r\n\r\nIssues that don't have enough info and can't be reproduced will be closed.\r\n\r\nYou can read more about issue submission guidelines here: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-submitting-an-issue\r\n-->\r\n\r\nhttps://github.com/compeek/angular-ivy-input-undefined-issue\r\n\r\nIf you compile this project, you should only see a compiler error about `null` and not about `undefined` as well. See `index.html` for some more explanation of the example.\r\n\r\nYou can reproduce this easily in any project with `strictNullChecks` turned on and the Ivy compiler enabled with these two components (from my minimal reproduction project):\r\n\r\n```\r\n@Component({\r\n selector: 'app-root',\r\n template: `\u003capp-child [stringOnlyInput1]=\"thisPropertyIsUndefined\" [stringOnlyInput2]=\"thisPropertyIsNull\">\u003c/app-child>`\r\n})\r\nexport class AppComponent {\r\n thisPropertyIsUndefined: undefined = undefined;\r\n thisPropertyIsNull: null = null;\r\n}\r\n\r\n@Component({\r\n selector: 'app-child',\r\n template: `\r\n {{ 'stringOnlyInput1: ' + stringOnlyInput1 }}\r\n \u003cbr>\r\n {{ 'stringOnlyInput2: ' + stringOnlyInput2 }}\r\n `\r\n})\r\nexport class ChildComponent {\r\n @Input() stringOnlyInput1: string = '';\r\n @Input() stringOnlyInput2: string = '';\r\n}\r\n```\r\n\r\nThe compiler should complain about the values passed to both inputs, but in fact it only complains about the `null` value and not `undefined`.\r\n\r\n## 🔥 Exception or Error\r\n\r\nI would expect an error like:\r\n`Type 'undefined' is not assignable to type 'string'.`\r\n\r\nBut none is thrown.\r\n\r\nAnd in fact if you do it with `null`, the error looks like this:\r\n`Type 'null' is not assignable to type 'string | undefined'.`\r\n\r\nNotice how it says it's not assignable to `string | undefined` even though the input type is just `string`.\r\n\r\n## 🌍 Your Environment\r\n\r\n**Angular Version:**\r\n\u003cpre>\u003ccode>\r\n\u003c!-- run `ng version` and paste output below -->\r\nAngular CLI: 9.0.0-next.4\r\nNode: 10.16.3\r\nOS: win32 x64\r\nAngular: 9.0.0-next.6\r\n... animations, common, compiler, compiler-cli, core\r\n... language-service, platform-browser, platform-browser-dynamic\r\n... router\r\n\r\nPackage Version\r\n-----------------------------------------------------------\r\n@angular-devkit/architect 0.900.0-next.4\r\n@angular-devkit/build-angular 0.900.0-next.4\r\n@angular-devkit/build-optimizer 0.900.0-next.4\r\n@angular-devkit/build-webpack 0.900.0-next.4\r\n@angular-devkit/core 9.0.0-next.4\r\n@angular-devkit/schematics 9.0.0-next.4\r\n@angular/cli 9.0.0-next.4\r\n@ngtools/webpack 9.0.0-next.4\r\n@schematics/angular 9.0.0-next.4\r\n@schematics/update 0.900.0-next.4\r\nrxjs 6.5.3\r\ntypescript 3.5.3\r\nwebpack 4.39.3\r\n\u003c/code>\u003c/pre>\r\n\r\n**Anything else relevant?**\r\n\u003c!-- ✍️Is this a browser specific issue? If so, please specify the browser and version. -->\r\n\r\n\u003c!-- ✍️Do any of these matter: operating system, IDE, package manager, HTTP server, ...? If so, please mention it below. -->\r\n","author":{"url":"https://github.com/compeek","@type":"Person","name":"compeek"},"datePublished":"2019-09-16T04:31:47Z","url":"https://github.com/angular/angular/issues/32690"}
| 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:f2f52d38-8a8f-97ca-a1d4-a970d17a3d68 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C5B2:60A6D:27AB6D:34BFBB:6B018CEA |
| html-safe-nonce | 2ff1bc5aba85417d8a7e0c80c4d88555a034b13b14f406700d12be0173fe1810 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNUIyOjYwQTZEOjI3QUI2RDozNEJGQkI6NkIwMThDRUEiLCJ2aXNpdG9yX2lkIjoiNjAwNDEyMjkzNDUwNTk5OTU5NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5e49dab67180ea4597beeeba5f3ab643135ee39e42bcb3219b203e77bc16a41d |
| hovercard-subject-tag | issue:493841472 |
| 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/32690/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62e203a20e98b9cf7da3df77692def007dc53cd8752b5f6e46384adb50055e59/angular/angular/issues/32690 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62e203a20e98b9cf7da3df77692def007dc53cd8752b5f6e46384adb50055e59/angular/angular/issues/32690 |
| og:image:alt | 🐞 bug report Affected Package Not exactly sure, but probably: @angular/compiler @angular/compiler-cli Is this a regression? No, from my experience, the old compiler didn't enforce strictNullChecks ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | compeek |
| 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