-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Description
Bug Report
Ionic version:
[x] 5.x
Current behavior:
Creating an IonItem and defining it as a button while using Angular's strict template type checking causes error TS2322 when running a dev server with ng serve or compiling with ng build [--prod].
<ion-item button>Test</ion-item>error TS2322: Type 'string' is not assignable to type 'boolean'.
Expected behavior:
No type error on compilation, even with strict template type checking.
Steps to reproduce:
Related code:
This type definition is the root of the issue:
https://github.com/ionic-team/ionic/blob/fbcd3f8c087420bc035f7b2f560659bc53a70a17/core/src/components.d.ts#L4276
Changing the type to a string fixes the issue, though I'm not sure how this would affect other use-cases:
"button"?: "" | "true" | "false"; Alternatively:
"button"?: "" | boolean; Here is a sample repo: https://github.com/athisun/angular-ivy-pybfcx. Note that the issue isn't reproducible in StackBlitz.
Other information:
Strict template type checking was introduced in and thus affects Angular 9+: https://angular.io/guide/template-typecheck#strict-mode. With Angular 10's new ng new --strict flag, many new projects will likely experience this issue.
I suspect this issue affects other Ionic components which allow attributes with no assigned value but also expect a non-string type.
Binding a boolean value to the attribute is a temporary alternative fix.
<ion-item [button]="true">Test</ion-item>Ionic info:
Ionic:
Ionic CLI : 6.10.1
Utility:
cordova-res : not installed
native-run : not installed
System:
NodeJS : v14.4.0
npm : 6.14.5
OS : macOS Catalina