-
Notifications
You must be signed in to change notification settings - Fork 6.8k
build: enable strict attribute type checking #17977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: enable strict attribute type checking #17977
Conversation
@@ -4,7 +4,7 @@ | |||
Default Slide Toggle | |||
</mat-slide-toggle> | |||
|
|||
<mat-slide-toggle [(ngModel)]="firstToggle" disabled> | |||
<mat-slide-toggle [(ngModel)]="firstToggle" [disabled]="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't the whole point of those coercion types to allow usages like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but in some cases where multiple directives are used on the same element, the union input type is used. In that case, the union of NgModel#disabled
and MatSlideToggle#disabled
is just boolean
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Shouldn't we fix NgModel
in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I brought this up in the past when I disabled this flag/when I tried early Ivy type checking, but I think we didn't decide on an action. My thinking is that this is not an issue of NgModel
. NgModel does not do coercion and ngtsc correctly reports that an empty string is not assignable.
Though we could say that this is such a common case in NgModel
and we should do it for convenience. Happy to send a PR if so. Ultimately though this feels like a general problem not specific to only NgModel
. There might be more other inputs in framework, or in third party libraries that cause these problems. Seems like another good reason for having something like @BooleanInput
in the future. cc. @jelbourn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to change NgModel
to follow our model for disabled
, but it is a breaking change and I think it's too late to make this change in v9. We just have to deal with it for now and file an issue to make the fix for v10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually just read about angular/angular#19929 and it looks like NgModel
already does coercion. So it seems like it would be the right thing to add a static coercion member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add the acceptance type, then, and then remove the disable
bits here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I created angular/angular#34438
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocked on angular/angular#34502 😞
d2b9dd6
to
53f7c6b
Compare
53f7c6b
to
f6ae8f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -4,7 +4,7 @@ | |||
Default Slide Toggle | |||
</mat-slide-toggle> | |||
|
|||
<mat-slide-toggle [(ngModel)]="firstToggle" disabled> | |||
<mat-slide-toggle [(ngModel)]="firstToggle" [disabled]="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love to change NgModel
to follow our model for disabled
, but it is a breaking change and I think it's too late to make this change in v9. We just have to deal with it for now and file an issue to make the fix for v10.
f6ae8f4
to
2c8531e
Compare
When we initially enabled strict template type checking in the components repository, we temporarily disabled the strict attribute type checking due to an issue with `NgModel` and the disabled input. This has been fixed in the recent rc v9.0.0-rc.7
2c8531e
to
6a544e7
Compare
This is finally green. @jelbourn we should get it in to ensure that we test our coerced inputs. |
When we initially enabled strict template type checking in the components repository, we temporarily disabled the strict attribute type checking due to an issue with `NgModel` and the disabled input. This has been fixed in the recent rc v9.0.0-rc.7
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
When we initially enabled strict template type checking in the
components repository, we temporarily disabled the strict attribute
type checking due to an issue with
NgModel
and the disabled input.NgModel
seems to behave as expected and the issue we are facing forsome elements where
NgModel#disabled
is incompatible with thedisabled input of Angular Material components (where string is allowed)
is correctly reported by ngtsc.
We can satisfy both input signatures and actually enable the flag to
catch attribute typing/coercion issues which are actually affecting
components we ship.