Skip to content
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

Enable strict template checks #2711

Merged
merged 11 commits into from
Feb 23, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ListItemComponent implements OnInit, AfterViewInit {

@Input() item: any;

@Input() boundaryClass: BoundaryClass;
@Input() boundaryClass: BoundaryClass | BoundaryClass[];

@Input() swipeActions: ListSwipeAction[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { Observable, of } from 'rxjs';

import { WindowRef } from '../../../types/window-ref';
import { ThemeColor } from '../../../helpers';

@Component({
selector: 'kirby-alert',
Expand Down Expand Up @@ -36,7 +37,7 @@ export class AlertComponent implements AfterViewInit {
}

@Input() iconName: string;
@Input() iconThemeColor: string;
@Input() iconThemeColor: ThemeColor;
@Input() okBtn: string;
@Input() okBtnIsDestructive: boolean;
@Input() cancelBtn: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
[attr.aria-label]="badge.description"
[themeColor]="badge.themeColor"
>
<ng-container *ngIf="badge.content.name; else badgeTextContent">
<ng-container *ngIf="$any(badge).content.name; else badgeTextContent">
mark-drastrup marked this conversation as resolved.
Show resolved Hide resolved
<kirby-icon
*ngIf="badge.content.isCustom; else defaultIconName"
[customName]="badge.content.name"
*ngIf="$any(badge).content.isCustom; else defaultIconName"
[customName]="$any(badge).content.name"
></kirby-icon>
<ng-template #defaultIconName>
<kirby-icon [name]="badge.content.name"></kirby-icon>
<kirby-icon [name]="$any(badge).content.name"></kirby-icon>
</ng-template>
</ng-container>
<ng-template #badgeTextContent>
{{ badge.content.text }}
{{ $any(badge).content.text }}
</ng-template>
</kirby-badge>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ReorderListComponent implements OnChanges, OnDestroy {

private setupDomListener() {
const callback = (mutationsList: any) => {
for (let mutation of mutationsList) {
for (const mutation of mutationsList) {
if (mutation.oldValue !== mutation.target['className']) {
this.reorderActive = mutation.target['className'].includes('reorder-list-active');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
>
<ng-container *ngIf="item.badge.icon; else badgeContent">
<kirby-icon
*ngIf="item.badge.isCustomIcon; else defaultIconName"
*ngIf="$any(item).badge.isCustomIcon; else defaultIconName"
mark-drastrup marked this conversation as resolved.
Show resolved Hide resolved
[customName]="item.badge.icon"
></kirby-icon>
<ng-template #defaultIconName>
Expand Down
3 changes: 2 additions & 1 deletion libs/designsystem/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictTemplates": true,
"strictDomEventTypes": false,
Copy link
Contributor Author

@mark-drastrup mark-drastrup Jan 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disabled strictDomEventTypes because it throws an error each time we try to access a property on a DOM event. Fx:

<input (change)="onChange($event.target.value)" />

All events are typed as a generic Event, which doesn't allow us to access $event.detail.checked or $event.target.value, which we do in many components. I did initially handle it by passing the event to the method and do the typing in there. That solution was a bit cumbersome, especially when doing it for Ionic events, that needs to be handled like this:

import { ItemReorderEventDetail } from '@ionic/angular';

doReorder(event: Event) {
  const customEvent = event as CustomEvent<ItemReorderEventDetail>;
  // replace event usages with customEvent
}

Since we have to type cast the event in the method, I think we lose the value of type checking the input in the template.

"strictInjectionParameters": true,
"enableResourceInlining": true,
"inlineSourceMap": true,
Expand Down