Skip to content

Commit 911ad40

Browse files
crisbetoalxhub
authored andcommitted
build: fix type checking issues in test code (angular#60481)
Fixes some type checking issues in our own testing code that weren't showing up, because `strictTemplates` was turned off. PR Close angular#60481
1 parent b26b0ab commit 911ad40

9 files changed

Lines changed: 30 additions & 27 deletions

File tree

modules/benchmarks/src/class_bindings/class_bindings.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ import {Component, Input} from '@angular/core';
3333
})
3434
export class ClassBindingsComponent {
3535
@Input() msg: string = '';
36-
@Input() list: string[] | null = null;
36+
@Input() list: {i: number; text: string}[] | null = null;
3737
}

modules/benchmarks/src/ng_template_outlet_context/ng2/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module")
21
load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test")
2+
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module")
33

44
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
55

66
ng_module(
77
name = "ng2",
88
srcs = glob(["*.ts"]),
9-
strict_templates = True,
109
tsconfig = "//modules/benchmarks:tsconfig-build.json",
1110
deps = [
1211
"//modules/benchmarks/src:util_lib",

modules/playground/src/gestures/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class GesturesCmp {
2020
pinchScale: number = 1;
2121
rotateAngle: number = 0;
2222

23-
onSwipe(event: HammerInput): void {
24-
this.swipeDirection = event.deltaX > 0 ? 'right' : 'left';
23+
onSwipe(event: Event): void {
24+
this.swipeDirection = (event as unknown as HammerInput).deltaX > 0 ? 'right' : 'left';
2525
}
2626

27-
onPinch(event: HammerInput): void {
28-
this.pinchScale = event.scale;
27+
onPinch(event: Event): void {
28+
this.pinchScale = (event as unknown as HammerInput).scale;
2929
}
3030

31-
onRotate(event: HammerInput): void {
32-
this.rotateAngle = event.rotation;
31+
onRotate(event: Event): void {
32+
this.rotateAngle = (event as unknown as HammerInput).rotation;
3333
}
3434
}
3535

modules/playground/src/jsonp/app/jsonp_comp.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import {HttpClient} from '@angular/common/http';
1010
import {Component} from '@angular/core';
1111

12+
interface Person {
13+
name: string;
14+
}
15+
1216
@Component({
1317
selector: 'jsonp-app',
1418
template: `
@@ -20,8 +24,8 @@ import {Component} from '@angular/core';
2024
standalone: false,
2125
})
2226
export class JsonpCmp {
23-
people: Object;
27+
people: Person[];
2428
constructor(http: HttpClient) {
25-
http.jsonp<Object>('./people.json', 'callback').subscribe((res: Object) => (this.people = res));
29+
http.jsonp('./people.json', 'callback').subscribe((res: Person[]) => (this.people = res));
2630
}
2731
}

modules/playground/src/key_events/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class KeyEventsApp {
3535
event.preventDefault();
3636
}
3737

38-
onShiftEnter(event: KeyboardEvent): void {
38+
onShiftEnter(event: Event): void {
3939
this.shiftEnter = true;
4040
event.preventDefault();
4141
}

packages/core/test/acceptance/authoring/signal_inputs_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe('signal inputs', () => {
179179
template: 'input:{{input()}}',
180180
})
181181
class InputComp {
182-
input = input.required<string>();
182+
input = input.required<number>();
183183

184184
constructor() {
185185
this.input();

packages/core/test/bundling/animation_world/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ import {BrowserModule, platformBrowser} from '@angular/platform-browser';
2525
standalone: false,
2626
})
2727
class MakeColorGreyDirective {
28-
@HostBinding('style.background-color') private _backgroundColor: string | null = null;
29-
@HostBinding('style.color') private _textColor: string | null = null;
28+
@HostBinding('style.background-color') protected backgroundColor: string | null = null;
29+
@HostBinding('style.color') protected textColor: string | null = null;
3030

3131
on() {
32-
this._backgroundColor = 'grey';
33-
this._textColor = 'black';
32+
this.backgroundColor = 'grey';
33+
this.textColor = 'black';
3434
}
3535

3636
off() {
37-
this._backgroundColor = null;
38-
this._textColor = null;
37+
this.backgroundColor = null;
38+
this.textColor = null;
3939
}
4040

4141
toggle() {
42-
this._backgroundColor ? this.off() : this.on();
42+
this.backgroundColor ? this.off() : this.on();
4343
}
4444
}
4545

@@ -57,7 +57,7 @@ class BoxWithOverriddenStylesComponent {
5757
this.onInActive();
5858
}
5959

60-
@HostListener('click', ['$event'])
60+
@HostListener('click')
6161
toggle() {
6262
if (this.active) {
6363
this.onInActive();

packages/core/test/bundling/todo/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TodoStore {
9595
<h1>todos</h1>
9696
<input class="new-todo" placeholder="What needs to be done?" autofocus=""
9797
[value]="newTodoText"
98-
(keyup)="$event.code == 'Enter' ? addTodo() : newTodoText = $event.target.value">
98+
(keyup)="$event.code == 'Enter' ? addTodo() : newTodoText = $any($event.target).value">
9999
</header>
100100
<section *ngIf="todoStore.todos.length > 0" class="main">
101101
<input *ngIf="todoStore.todos.length"
@@ -117,7 +117,7 @@ class TodoStore {
117117
class="edit" #editedtodo
118118
[value]="todo.title"
119119
(blur)="stopEditing(todo, editedtodo.value)"
120-
(keyup)="todo.title = $event.target.value"
120+
(keyup)="todo.title = $any($event.target).value"
121121
(keyup)="$event.code == 'Enter' && updateEditingTodo(todo, editedtodo.value)"
122122
(keyup)="$event.code == 'Escape' && cancelEditingTodo(todo)">
123123
</li>

packages/core/test/bundling/todo_i18n/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class TodoStore {
8888
<h1>todos</h1>
8989
<input class="new-todo" i18n-placeholder placeholder="What needs to be done?" autofocus=""
9090
[value]="newTodoText"
91-
(keyup)="$event.code == 'Enter' ? addTodo() : updateNewTodoValue($event.target.value)">
91+
(keyup)="$event.code == 'Enter' ? addTodo() : updateNewTodoValue($event)">
9292
</header>
9393
<section *ngIf="todoStore.todos.length > 0" class="main">
9494
<input *ngIf="todoStore.todos.length"
@@ -110,7 +110,7 @@ class TodoStore {
110110
class="edit" #editedtodo
111111
[value]="todo.title"
112112
(blur)="updateEditedTodoValue(todo, editedtodo.value)"
113-
(keyup)="updateEditedTodoValue(todo, $event.target.value)"
113+
(keyup)="updateEditedTodoValue(todo, $any($event.target).value)"
114114
(keyup)="$event.code == 'Enter' && updateEditedTodoValue(todo, editedtodo.value)"
115115
(keyup)="$event.code == 'Escape' && cancelEditingTodo(todo)">
116116
</li>
@@ -192,8 +192,8 @@ class ToDoAppComponent {
192192
this.cdr.detectChanges();
193193
}
194194

195-
updateNewTodoValue(value: string) {
196-
this.newTodoText = value;
195+
updateNewTodoValue(event: Event) {
196+
this.newTodoText = (event.target as HTMLInputElement).value;
197197
this.cdr.detectChanges();
198198
}
199199
}

0 commit comments

Comments
 (0)