Skip to content

Commit 8da64f4

Browse files
devversionandrewseguin
authored andcommitted
feat: expand input types with coercion to work with ngtsc input type checking (#17528)
* feat: expand input types with coercion to work with ngtsc input type checking * refactor: add workaround for strict metadata emit of coercion static members See: angular/angular#33451 * build: patch ng_module bazel rule to enable strict template type checking Workaround for: angular/angular#33452 * refactor: disable strict metadata emit for legacy build output Workaround for angular/angular#33451. This makes sense at the current time since the Bazel output does *never* work with strict metadata emit... and considering that with Ivy there is no metadata anyway, it could be disabled in the meanwhile. * build: disable strict attribute type checking We are temporarily disabling strict attribute type checking since we have a few templates that set a coerced input while the `NgModel` directive is applied. In those cases, the empty string for the `disabled` input, is not assignable to the `NgModel#disabled` input, since it does not do coercion. We need to figure out what to do in those scenarios.
1 parent ed6f133 commit 8da64f4

File tree

237 files changed

+694
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

237 files changed

+694
-155
lines changed

src/a11y-demo/datepicker/datepicker-a11y.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ export class DatepickerAccessibilityDemo {
3131
appointmentDate: Date;
3232
minAppointmentDate = new Date();
3333
maxAppointmentDate = new Date(Date.now() + 365 * 24 * 60 * 60 * 1000);
34-
weekdaysOnly = (d: Date) => d.getDay() != 0 && d.getDay() != 6;
34+
weekdaysOnly = (d: Date|null) => d !== null && d.getDay() != 0 && d.getDay() != 6;
3535
}

src/cdk-experimental/dialog/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
],
77
"angularCompilerOptions": {
88
"annotateForClosureCompiler": true,
9-
"strictMetadataEmit": true,
109
"flatModuleOutFile": "index.js",
1110
"flatModuleId": "@angular/cdk-experimental/dialog",
1211
"skipTemplateCodegen": true,

src/cdk-experimental/popover-edit/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
],
77
"angularCompilerOptions": {
88
"annotateForClosureCompiler": true,
9-
"strictMetadataEmit": true,
109
"flatModuleOutFile": "index.js",
1110
"flatModuleId": "@angular/cdk-experimental/popover-edit",
1211
"skipTemplateCodegen": true,

src/cdk-experimental/scrolling/auto-size-virtual-scroll.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,7 @@ export class CdkAutoSizeVirtualScroll implements OnChanges {
463463
ngOnChanges() {
464464
this._scrollStrategy.updateBufferSize(this.minBufferPx, this.maxBufferPx);
465465
}
466+
467+
static ngAcceptInputType_minBufferPx: number | string;
468+
static ngAcceptInputType_maxBufferPx: number | string;
466469
}

src/cdk-experimental/scrolling/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk-experimental/scrolling",
1110
"skipTemplateCodegen": true,

src/cdk-experimental/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"angularCompilerOptions": {
2525
"enableIvy": false,
2626
"annotateForClosureCompiler": true,
27-
"strictMetadataEmit": true,
2827
"flatModuleOutFile": "index.js",
2928
"flatModuleId": "@angular/cdk-experimental",
3029
"skipTemplateCodegen": true,

src/cdk-experimental/tsconfig-tests.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
}
1515
},
1616
"angularCompilerOptions": {
17-
"strictMetadataEmit": true,
1817
"skipTemplateCodegen": true,
1918
"emitDecoratorMetadata": true,
2019

src/cdk/a11y/focus-trap/focus-trap.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,7 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit, DoCheck {
418418
this.focusTrap.attachAnchors();
419419
}
420420
}
421+
422+
static ngAcceptInputType_enabled: boolean | string;
423+
static ngAcceptInputType_autoCapture: boolean | string;
421424
}

src/cdk/a11y/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/a11y",
1110
"skipTemplateCodegen": true,

src/cdk/accordion/accordion-item.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,7 @@ export class CdkAccordionItem implements OnDestroy {
152152
}
153153
});
154154
}
155+
156+
static ngAcceptInputType_expanded: boolean | string;
157+
static ngAcceptInputType_disabled: boolean | string;
155158
}

src/cdk/accordion/accordion.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ export class CdkAccordion implements OnDestroy, OnChanges {
5959
this._openCloseAllActions.next(expanded);
6060
}
6161
}
62+
63+
static ngAcceptInputType_multi: boolean | string;
6264
}

src/cdk/accordion/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/accordion",
1110
"skipTemplateCodegen": true,

src/cdk/bidi/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/bidi",
1110
"skipTemplateCodegen": true,

src/cdk/clipboard/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
],
77
"angularCompilerOptions": {
88
"annotateForClosureCompiler": true,
9-
"strictMetadataEmit": true,
109
"flatModuleOutFile": "index.js",
1110
"flatModuleId": "@angular/cdk/clipboard",
1211
"skipTemplateCodegen": true,

src/cdk/coercion/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/coercion",
1110
"skipTemplateCodegen": true,

src/cdk/collections/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/collections",
1110
"skipTemplateCodegen": true,

src/cdk/drag-drop/directives/drag-handle.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ export class CdkDragHandle implements OnDestroy {
4646
ngOnDestroy() {
4747
this._stateChanges.complete();
4848
}
49+
50+
static ngAcceptInputType_disabled: boolean | string;
4951
}

src/cdk/drag-drop/directives/drag.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
408408
});
409409
});
410410
}
411+
412+
static ngAcceptInputType_disabled: boolean | string;
411413
}
412414

413415
/** Gets the closest ancestor of an element that matches a selector. */

src/cdk/drag-drop/directives/drop-list-group.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ export class CdkDropListGroup<T> implements OnDestroy {
3434
ngOnDestroy() {
3535
this._items.clear();
3636
}
37+
38+
static ngAcceptInputType_disabled: boolean | string;
3739
}

src/cdk/drag-drop/directives/drop-list.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,7 @@ export class CdkDropList<T = any> implements AfterContentInit, OnDestroy {
328328
});
329329
}
330330

331+
static ngAcceptInputType_disabled: boolean | string;
332+
static ngAcceptInputType_sortingDisabled: boolean | string;
333+
static ngAcceptInputType_autoScrollDisabled: boolean | string;
331334
}

src/cdk/drag-drop/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/drag-drop",
1110
"skipTemplateCodegen": true,

src/cdk/keycodes/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/keycodes",
1110
"skipTemplateCodegen": true,

src/cdk/layout/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/layout",
1110
"skipTemplateCodegen": true,

src/cdk/observers/observe-content.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
193193
this._currentSubscription.unsubscribe();
194194
}
195195
}
196+
197+
static ngAcceptInputType_disabled: boolean | string;
198+
static ngAcceptInputType_debounce: boolean | string;
196199
}
197200

198201

src/cdk/observers/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/observers",
1110
"skipTemplateCodegen": true,

src/cdk/overlay/overlay-directives.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
383383

384384
this._backdropSubscription.unsubscribe();
385385
}
386+
387+
static ngAcceptInputType_hasBackdrop: boolean | string;
388+
static ngAcceptInputType_lockPosition: boolean | string;
389+
static ngAcceptInputType_flexibleDimensions: boolean | string;
390+
static ngAcceptInputType_growAfterOpen: boolean | string;
391+
static ngAcceptInputType_push: boolean | string;
386392
}
387393

388394

src/cdk/overlay/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/overlay",
1110
"skipTemplateCodegen": true,

src/cdk/platform/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/platform",
1110
"skipTemplateCodegen": true,

src/cdk/portal/portal-directives.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ export class CdkPortalOutlet extends BasePortalOutlet implements OnInit, OnDestr
170170

171171
return viewRef;
172172
}
173+
174+
static ngAcceptInputType_portal: Portal<any> | null | undefined | '';
173175
}
174176

175177
/**

src/cdk/portal/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/portal",
1110
"skipTemplateCodegen": true,

src/cdk/scrolling/fixed-size-virtual-scroll.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,8 @@ export class CdkFixedSizeVirtualScroll implements OnChanges {
203203
ngOnChanges() {
204204
this._scrollStrategy.updateItemAndBufferSize(this.itemSize, this.minBufferPx, this.maxBufferPx);
205205
}
206+
207+
static ngAcceptInputType_itemSize: string | number;
208+
static ngAcceptInputType_minBufferPx: string | number;
209+
static ngAcceptInputType_maxBufferPx: string | number;
206210
}

src/cdk/scrolling/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
],
77
"angularCompilerOptions": {
88
"annotateForClosureCompiler": true,
9-
"strictMetadataEmit": true,
109
"flatModuleOutFile": "index.js",
1110
"flatModuleId": "@angular/cdk/scrolling",
1211
"skipTemplateCodegen": true,

src/cdk/stepper/stepper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ export class CdkStep implements OnChanges {
231231
// underlying MatStepHeader, we have to make sure that change detection runs correctly.
232232
this._stepper._stateChanged();
233233
}
234+
235+
static ngAcceptInputType_editable: boolean | string;
236+
static ngAcceptInputType_hasError: boolean | string;
237+
static ngAcceptInputType_optional: boolean | string;
238+
static ngAcceptInputType_completed: boolean | string;
234239
}
235240

236241
@Directive({
@@ -519,6 +524,13 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
519524
const focusedElement = this._document.activeElement;
520525
return stepperElement === focusedElement || stepperElement.contains(focusedElement);
521526
}
527+
528+
static ngAcceptInputType_editable: boolean | string;
529+
static ngAcceptInputType_optional: boolean | string;
530+
static ngAcceptInputType_completed: boolean | string;
531+
static ngAcceptInputType_hasError: boolean | string;
532+
static ngAcceptInputType_linear: boolean | string;
533+
static ngAcceptInputType_selectedIndex: number | string;
522534
}
523535

524536

src/cdk/stepper/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
],
77
"angularCompilerOptions": {
88
"annotateForClosureCompiler": true,
9-
"strictMetadataEmit": true,
109
"flatModuleOutFile": "index.js",
1110
"flatModuleId": "@angular/cdk/stepper",
1211
"skipTemplateCodegen": true,

src/cdk/table/cell.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export class CdkColumnDef extends _CdkColumnDefBase implements CanStick {
107107
* do not match are replaced by the '-' character.
108108
*/
109109
cssClassFriendlyName: string;
110+
111+
static ngAcceptInputType_sticky: boolean | string;
112+
static ngAcceptInputType_stickyEnd: boolean | string;
110113
}
111114

112115
/** Base class for the cells. Adds a CSS classname that identifies the column it renders in. */

src/cdk/table/row.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export class CdkHeaderRowDef extends _CdkHeaderRowDefBase implements CanStick, O
9999
ngOnChanges(changes: SimpleChanges): void {
100100
super.ngOnChanges(changes);
101101
}
102+
103+
static ngAcceptInputType_sticky: boolean | string;
102104
}
103105

104106
// Boilerplate for applying mixins to CdkFooterRowDef.
@@ -125,6 +127,8 @@ export class CdkFooterRowDef extends _CdkFooterRowDefBase implements CanStick, O
125127
ngOnChanges(changes: SimpleChanges): void {
126128
super.ngOnChanges(changes);
127129
}
130+
131+
static ngAcceptInputType_sticky: boolean | string;
128132
}
129133

130134
/**

src/cdk/table/table.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,8 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
10771077
this.updateStickyColumnStyles();
10781078
});
10791079
}
1080+
1081+
static ngAcceptInputType_multiTemplateDataRows: boolean | string;
10801082
}
10811083

10821084
/** Utility function that gets a merged list of the entries in a QueryList and values of a Set. */

src/cdk/table/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
],
77
"angularCompilerOptions": {
88
"annotateForClosureCompiler": true,
9-
"strictMetadataEmit": true,
109
"flatModuleOutFile": "index.js",
1110
"flatModuleId": "@angular/cdk/table",
1211
"skipTemplateCodegen": true,

src/cdk/testing/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
],
77
"angularCompilerOptions": {
88
"annotateForClosureCompiler": true,
9-
"strictMetadataEmit": true,
109
"flatModuleOutFile": "index.js",
1110
"flatModuleId": "@angular/cdk/testing",
1211
"skipTemplateCodegen": true,

src/cdk/text-field/autosize.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
9+
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
1010
import {
1111
Directive,
1212
ElementRef,
@@ -56,15 +56,15 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
5656
@Input('cdkAutosizeMinRows')
5757
get minRows(): number { return this._minRows; }
5858
set minRows(value: number) {
59-
this._minRows = value;
59+
this._minRows = coerceNumberProperty(value);
6060
this._setMinHeight();
6161
}
6262

6363
/** Maximum amount of rows in the textarea. */
6464
@Input('cdkAutosizeMaxRows')
6565
get maxRows(): number { return this._maxRows; }
6666
set maxRows(value: number) {
67-
this._maxRows = value;
67+
this._maxRows = coerceNumberProperty(value);
6868
this._setMaxHeight();
6969
}
7070

@@ -272,4 +272,8 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
272272
textarea.setSelectionRange(selectionStart, selectionEnd);
273273
}
274274
}
275+
276+
static ngAcceptInputType_minRows: number | string;
277+
static ngAcceptInputType_maxRows: number | string;
278+
static ngAcceptInputType_enabled: boolean | string;
275279
}

src/cdk/text-field/tsconfig-build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
],
66
"angularCompilerOptions": {
77
"annotateForClosureCompiler": true,
8-
"strictMetadataEmit": true,
98
"flatModuleOutFile": "index.js",
109
"flatModuleId": "@angular/cdk/text-field",
1110
"skipTemplateCodegen": true,

src/cdk/tree/padding.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,6 @@ export class CdkTreeNodePadding<T> implements OnDestroy {
109109
this._currentPadding = padding;
110110
}
111111
}
112+
113+
static ngAcceptInputType_level: number | string;
112114
}

0 commit comments

Comments
 (0)