Repository navigation
Closed
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimefeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
Milestone
Description
I'm submitting a...
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ x ] Bug report
[ x ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Property binding doesn't check types when compiling.
Expected behavior
Property binding shows some error when you bind an incorrect type
Minimal reproduction of the problem with instructions
JIT:
https://plnkr.co/edit/JQbbBH0DcRA5fEwchn5L?p=preview
AoT:
https://github.com/rinfan/input-property-binding-broken
Reproduction steps:
- download my repo
- npm install
- npm run start
- navigate to localhost:4201
Everything compiled fine with AoT, even though the second input child component has a date entered for the number @input field.
I would expect that using a non-number as input to "InputChild"'s Input would show some kind of warning or error.
What is the motivation / use case for changing the behavior?
Better type safety
Sorry if there another issue or tsconfig/cli config json property I can set for this.
Environment
Plunker, this problem seems to happen with both the JIT and AOT in my project.
Angular version: 5.0.3 (I think it was an issue in 4.* too though)
Browser:
- [x ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX (on nightly it seems like plunker is broken but I don't think thats your problem)
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ x] IE version 11
- [ ] Edge version XX
Reacted by Nathan Giebel, Trotyl Yu, Valeriy Katkov, Den Klimovsky, Bruno Devaux, Nathan Phillip Brink, saint1991, Colin Kahn, Ingo Bürk, Ben M and 1 more
Reacted by bushuyev and Colin Kahn
Metadata
Metadata
Assignees
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimefeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
Activity
mhevery commentedon Nov 28, 2017
your plunker example is running in JIT mode which does no type checking. In AoT mode (which can be only done through the cli right now, you should get an error.)
rinfan commentedon Nov 30, 2017
@mhevery
Sorry I should have added an AoT example in my original post.
https://github.com/rinfan/input-property-binding-broken
Is it possibly I have the wrong .angular-cli or tsconfig settings to get types on property binding?
Reproduction steps:
@Inputfield.trotyl commentedon Nov 30, 2017
Can be reproduced in edit.ng which is using AOT:
Should indeed be an Angular problem.
@rinfan Could you add your repro repo to the original issue body and reopen it?
trotyl commentedon Nov 30, 2017
From #19929 it's clearly there is currently NO type checking for
@Input()properties, otherwise it would not be possible to assign an empty string tobooleanproperty.rinfan commentedon Nov 30, 2017
@trotyl I don't think I can reopen it because someone else closed it.
But I did add the AoT repro steps to the OP, good idea.
rinfan commentedon Dec 2, 2017
@mhevery please unclose this, I provided an AOT example of it being broken.
Stouffi commentedon Feb 15, 2018
@mhevery Could you please consider reopening this issue?
With the fullTemplateTypeCheck compiler option at true, I expected that I couldn't assign an incompatible type to a property binding of a component/directive.
This unsafe behavior can lead to numerous errors at runtime and is a real pain for a large application with many components.
sdharmavarapu commentedon Apr 12, 2018
Yes, this issue has been observed in 4.* too
pauldraper commentedon Jul 14, 2019
Not only it is observed in 4, it was introduced in 4.
In other words, this is a regression currently headed into its 28th month.
With how easily this got by the regression test suite, it's amazing that Ivy is taking as long to pass them as it is.
petebacondarwin commentedon Jul 15, 2019
The new compiler (supporting ivy) type checker is more restrictive and should enforce these type constraints on
@Input()properties. Can you try compiling with full type checking and ivy enabled?rinfan commentedon Jul 28, 2019
Wow, I completely forgot about this issue and figured it ended up in a never fix bucket. I'm pleasantly surprised that it works now! Thanks a lot @petebacondarwin(and to @trotyl for making the followup issues I was too lazy to do)! I'm totes fine with this being closed again.
For future people who might run into this issue:
Using:
While the error is somewhat cryptic(it might be nice if it pointed to the template line as opposed to some generated constructor), its there and stops compilation with an error!
Using components that look something like:
petebacondarwin commentedon Jul 28, 2019
Glad you are unlocked, as it were.
angular-automatic-lock-bot commentedon Sep 15, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.