Skip to content

Commit 49a1324

Browse files
devversionmmalerba
authored andcommitted
refactor: switch acceptance members to type aliases (#17653)
* refactor: switch acceptance members to type aliases Instead of manually typing the union types for boolean and number inputs, we should use a type alias. This allows us to make changes easier in the future, and it avoids a lot of repetition. * fixup! refactor: switch acceptance members to type aliases Update goldens * fix rebase issue
1 parent 6ab8e36 commit 49a1324

File tree

137 files changed

+683
-577
lines changed

Some content is hidden

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

137 files changed

+683
-577
lines changed

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

+3-3
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 {coerceNumberProperty} from '@angular/cdk/coercion';
9+
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
1010
import {ListRange} from '@angular/cdk/collections';
1111
import {
1212
CdkVirtualScrollViewport,
@@ -464,6 +464,6 @@ export class CdkAutoSizeVirtualScroll implements OnChanges {
464464
this._scrollStrategy.updateBufferSize(this.minBufferPx, this.maxBufferPx);
465465
}
466466

467-
static ngAcceptInputType_minBufferPx: number | string | null | undefined;
468-
static ngAcceptInputType_maxBufferPx: number | string | null | undefined;
467+
static ngAcceptInputType_minBufferPx: NumberInput;
468+
static ngAcceptInputType_maxBufferPx: NumberInput;
469469
}

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

+3-3
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 {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1010
import {DOCUMENT} from '@angular/common';
1111
import {
1212
AfterContentInit,
@@ -419,6 +419,6 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit, DoCheck {
419419
}
420420
}
421421

422-
static ngAcceptInputType_enabled: boolean | string | null | undefined;
423-
static ngAcceptInputType_autoCapture: boolean | string | null | undefined;
422+
static ngAcceptInputType_enabled: BooleanInput;
423+
static ngAcceptInputType_autoCapture: BooleanInput;
424424
}

src/cdk/accordion/accordion-item.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '@angular/core';
1919
import {UniqueSelectionDispatcher} from '@angular/cdk/collections';
2020
import {CdkAccordion} from './accordion';
21-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
21+
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
2222
import {Subscription} from 'rxjs';
2323

2424
/** Used to generate unique ID for each accordion item. */
@@ -153,6 +153,6 @@ export class CdkAccordionItem implements OnDestroy {
153153
});
154154
}
155155

156-
static ngAcceptInputType_expanded: boolean | string | null | undefined;
157-
static ngAcceptInputType_disabled: boolean | string | null | undefined;
156+
static ngAcceptInputType_expanded: BooleanInput;
157+
static ngAcceptInputType_disabled: BooleanInput;
158158
}

src/cdk/accordion/accordion.ts

+2-2
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 {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1010
import {Directive, Input, OnChanges, OnDestroy, SimpleChanges} from '@angular/core';
1111
import {Subject} from 'rxjs';
1212

@@ -60,5 +60,5 @@ export class CdkAccordion implements OnDestroy, OnChanges {
6060
}
6161
}
6262

63-
static ngAcceptInputType_multi: boolean | string | null | undefined;
63+
static ngAcceptInputType_multi: BooleanInput;
6464
}

src/cdk/coercion/boolean-property.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
/**
10+
* Type describing the allowed values for a boolean input.
11+
* @docs-private
12+
*/
13+
export type BooleanInput = string | boolean | null | undefined;
14+
915
/** Coerces a data-bound value (typically a string) to a boolean. */
1016
export function coerceBooleanProperty(value: any): boolean {
1117
return value != null && `${value}` !== 'false';

src/cdk/coercion/number-property.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
/**
10+
* Type describing the allowed values for a number input
11+
* @docs-private
12+
*/
13+
export type NumberInput = string | number | null | undefined;
14+
915
/** Coerces a data-bound value (typically a string) to a number. */
1016
export function coerceNumberProperty(value: any): number;
1117
export function coerceNumberProperty<D>(value: any, fallback: D): number | D;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Directive, ElementRef, Inject, Optional, Input, OnDestroy} from '@angular/core';
10-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1111
import {Subject} from 'rxjs';
1212
import {CDK_DRAG_PARENT} from '../drag-parent';
1313
import {toggleNativeDragInteractions} from '../drag-styling';
@@ -47,5 +47,5 @@ export class CdkDragHandle implements OnDestroy {
4747
this._stateChanges.complete();
4848
}
4949

50-
static ngAcceptInputType_disabled: boolean | string | null | undefined;
50+
static ngAcceptInputType_disabled: BooleanInput;
5151
}

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ import {
3030
ChangeDetectorRef,
3131
isDevMode,
3232
} from '@angular/core';
33-
import {coerceBooleanProperty, coerceNumberProperty, coerceElement} from '@angular/cdk/coercion';
33+
import {
34+
coerceBooleanProperty,
35+
coerceNumberProperty,
36+
coerceElement,
37+
BooleanInput
38+
} from '@angular/cdk/coercion';
3439
import {Observable, Observer, Subject, merge} from 'rxjs';
3540
import {startWith, take, map, takeUntil, switchMap, tap} from 'rxjs/operators';
3641
import {
@@ -409,7 +414,7 @@ export class CdkDrag<T = any> implements AfterViewInit, OnChanges, OnDestroy {
409414
});
410415
}
411416

412-
static ngAcceptInputType_disabled: boolean | string | null | undefined;
417+
static ngAcceptInputType_disabled: BooleanInput;
413418
}
414419

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Directive, OnDestroy, Input} from '@angular/core';
10-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1111

1212
/**
1313
* Declaratively connects sibling `cdkDropList` instances together. All of the `cdkDropList`
@@ -35,5 +35,5 @@ export class CdkDropListGroup<T> implements OnDestroy {
3535
this._items.clear();
3636
}
3737

38-
static ngAcceptInputType_disabled: boolean | string | null | undefined;
38+
static ngAcceptInputType_disabled: BooleanInput;
3939
}

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

+4-4
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 {coerceArray, coerceBooleanProperty} from '@angular/cdk/coercion';
9+
import {BooleanInput, coerceArray, coerceBooleanProperty} from '@angular/cdk/coercion';
1010
import {
1111
ContentChildren,
1212
ElementRef,
@@ -332,7 +332,7 @@ export class CdkDropList<T = any> implements AfterContentInit, OnDestroy {
332332
});
333333
}
334334

335-
static ngAcceptInputType_disabled: boolean | string | null | undefined;
336-
static ngAcceptInputType_sortingDisabled: boolean | string | null | undefined;
337-
static ngAcceptInputType_autoScrollDisabled: boolean | string | null | undefined;
335+
static ngAcceptInputType_disabled: BooleanInput;
336+
static ngAcceptInputType_sortingDisabled: BooleanInput;
337+
static ngAcceptInputType_autoScrollDisabled: BooleanInput;
338338
}

src/cdk/observers/observe-content.ts

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

9-
import {coerceBooleanProperty, coerceNumberProperty, coerceElement} from '@angular/cdk/coercion';
9+
import {
10+
coerceBooleanProperty,
11+
coerceNumberProperty,
12+
coerceElement,
13+
BooleanInput
14+
} from '@angular/cdk/coercion';
1015
import {
1116
AfterContentInit,
1217
Directive,
@@ -194,8 +199,8 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
194199
}
195200
}
196201

197-
static ngAcceptInputType_disabled: boolean | string | null | undefined;
198-
static ngAcceptInputType_debounce: boolean | string | null | undefined;
202+
static ngAcceptInputType_disabled: BooleanInput;
203+
static ngAcceptInputType_debounce: BooleanInput;
199204
}
200205

201206

src/cdk/overlay/overlay-directives.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Direction, Directionality} from '@angular/cdk/bidi';
10-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1111
import {ESCAPE, hasModifierKey} from '@angular/cdk/keycodes';
1212
import {TemplatePortal} from '@angular/cdk/portal';
1313
import {
@@ -395,11 +395,11 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
395395
this._backdropSubscription.unsubscribe();
396396
}
397397

398-
static ngAcceptInputType_hasBackdrop: boolean | string | null | undefined;
399-
static ngAcceptInputType_lockPosition: boolean | string | null | undefined;
400-
static ngAcceptInputType_flexibleDimensions: boolean | string | null | undefined;
401-
static ngAcceptInputType_growAfterOpen: boolean | string | null | undefined;
402-
static ngAcceptInputType_push: boolean | string | null | undefined;
398+
static ngAcceptInputType_hasBackdrop: BooleanInput;
399+
static ngAcceptInputType_lockPosition: BooleanInput;
400+
static ngAcceptInputType_flexibleDimensions: BooleanInput;
401+
static ngAcceptInputType_growAfterOpen: BooleanInput;
402+
static ngAcceptInputType_push: BooleanInput;
403403
}
404404

405405

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

+4-4
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 {coerceNumberProperty} from '@angular/cdk/coercion';
9+
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
1010
import {Directive, forwardRef, Input, OnChanges} from '@angular/core';
1111
import {Observable, Subject} from 'rxjs';
1212
import {distinctUntilChanged} from 'rxjs/operators';
@@ -204,7 +204,7 @@ export class CdkFixedSizeVirtualScroll implements OnChanges {
204204
this._scrollStrategy.updateItemAndBufferSize(this.itemSize, this.minBufferPx, this.maxBufferPx);
205205
}
206206

207-
static ngAcceptInputType_itemSize: string | number | null | undefined;
208-
static ngAcceptInputType_minBufferPx: string | number | null | undefined;
209-
static ngAcceptInputType_maxBufferPx: string | number | null | undefined;
207+
static ngAcceptInputType_itemSize: NumberInput;
208+
static ngAcceptInputType_minBufferPx: NumberInput;
209+
static ngAcceptInputType_maxBufferPx: NumberInput;
210210
}

src/cdk/stepper/stepper.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
import {FocusableOption, FocusKeyManager} from '@angular/cdk/a11y';
1010
import {Direction, Directionality} from '@angular/cdk/bidi';
11-
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
11+
import {
12+
BooleanInput,
13+
coerceBooleanProperty,
14+
coerceNumberProperty,
15+
NumberInput
16+
} from '@angular/cdk/coercion';
1217
import {END, ENTER, hasModifierKey, HOME, SPACE} from '@angular/cdk/keycodes';
1318
import {DOCUMENT} from '@angular/common';
1419
import {
@@ -231,10 +236,10 @@ export class CdkStep implements OnChanges {
231236
this._stepper._stateChanged();
232237
}
233238

234-
static ngAcceptInputType_editable: boolean | string | null | undefined;
235-
static ngAcceptInputType_hasError: boolean | string | null | undefined;
236-
static ngAcceptInputType_optional: boolean | string | null | undefined;
237-
static ngAcceptInputType_completed: boolean | string | null | undefined;
239+
static ngAcceptInputType_editable: BooleanInput;
240+
static ngAcceptInputType_hasError: BooleanInput;
241+
static ngAcceptInputType_optional: BooleanInput;
242+
static ngAcceptInputType_completed: BooleanInput;
238243
}
239244

240245
@Directive({
@@ -518,12 +523,12 @@ export class CdkStepper implements AfterViewInit, OnDestroy {
518523
return stepperElement === focusedElement || stepperElement.contains(focusedElement);
519524
}
520525

521-
static ngAcceptInputType_editable: boolean | string | null | undefined;
522-
static ngAcceptInputType_optional: boolean | string | null | undefined;
523-
static ngAcceptInputType_completed: boolean | string | null | undefined;
524-
static ngAcceptInputType_hasError: boolean | string | null | undefined;
525-
static ngAcceptInputType_linear: boolean | string | null | undefined;
526-
static ngAcceptInputType_selectedIndex: number | string | null | undefined;
526+
static ngAcceptInputType_editable: BooleanInput;
527+
static ngAcceptInputType_optional: BooleanInput;
528+
static ngAcceptInputType_completed: BooleanInput;
529+
static ngAcceptInputType_hasError: BooleanInput;
530+
static ngAcceptInputType_linear: BooleanInput;
531+
static ngAcceptInputType_selectedIndex: NumberInput;
527532
}
528533

529534

src/cdk/table/cell.ts

+3-3
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 {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1010
import {ContentChild, Directive, ElementRef, Input, TemplateRef} from '@angular/core';
1111
import {CanStick, CanStickCtor, mixinHasStickyInput} from './can-stick';
1212

@@ -108,8 +108,8 @@ export class CdkColumnDef extends _CdkColumnDefBase implements CanStick {
108108
*/
109109
cssClassFriendlyName: string;
110110

111-
static ngAcceptInputType_sticky: boolean | string | null | undefined;
112-
static ngAcceptInputType_stickyEnd: boolean | string | null | undefined;
111+
static ngAcceptInputType_sticky: BooleanInput;
112+
static ngAcceptInputType_stickyEnd: BooleanInput;
113113
}
114114

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

src/cdk/table/row.ts

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

9+
import {BooleanInput} from '@angular/cdk/coercion';
910
import {
1011
ChangeDetectionStrategy,
1112
Component,
@@ -100,7 +101,7 @@ export class CdkHeaderRowDef extends _CdkHeaderRowDefBase implements CanStick, O
100101
super.ngOnChanges(changes);
101102
}
102103

103-
static ngAcceptInputType_sticky: boolean | string | null | undefined;
104+
static ngAcceptInputType_sticky: BooleanInput;
104105
}
105106

106107
// Boilerplate for applying mixins to CdkFooterRowDef.
@@ -128,7 +129,7 @@ export class CdkFooterRowDef extends _CdkFooterRowDefBase implements CanStick, O
128129
super.ngOnChanges(changes);
129130
}
130131

131-
static ngAcceptInputType_sticky: boolean | string | null | undefined;
132+
static ngAcceptInputType_sticky: BooleanInput;
132133
}
133134

134135
/**

src/cdk/table/table.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Direction, Directionality} from '@angular/cdk/bidi';
10-
import {coerceBooleanProperty} from '@angular/cdk/coercion';
10+
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
1111
import {CollectionViewer, DataSource, isDataSource} from '@angular/cdk/collections';
1212
import {Platform} from '@angular/cdk/platform';
1313
import {DOCUMENT} from '@angular/common';
@@ -1077,7 +1077,7 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
10771077
});
10781078
}
10791079

1080-
static ngAcceptInputType_multiTemplateDataRows: boolean | string | null | undefined;
1080+
static ngAcceptInputType_multiTemplateDataRows: BooleanInput;
10811081
}
10821082

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

src/cdk/text-field/autosize.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';
9+
import {
10+
BooleanInput,
11+
coerceBooleanProperty,
12+
coerceNumberProperty,
13+
NumberInput
14+
} from '@angular/cdk/coercion';
1015
import {
1116
Directive,
1217
ElementRef,
@@ -281,7 +286,7 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
281286
}
282287
}
283288

284-
static ngAcceptInputType_minRows: number | string | null | undefined;
285-
static ngAcceptInputType_maxRows: number | string | null | undefined;
286-
static ngAcceptInputType_enabled: boolean | string | null | undefined;
289+
static ngAcceptInputType_minRows: NumberInput;
290+
static ngAcceptInputType_maxRows: NumberInput;
291+
static ngAcceptInputType_enabled: BooleanInput;
287292
}

src/cdk/tree/padding.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {Directionality} from '@angular/cdk/bidi';
10-
import {coerceNumberProperty} from '@angular/cdk/coercion';
10+
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
1111
import {Directive, ElementRef, Input, OnDestroy, Optional, Renderer2} from '@angular/core';
1212
import {takeUntil} from 'rxjs/operators';
1313
import {Subject} from 'rxjs';
@@ -110,5 +110,5 @@ export class CdkTreeNodePadding<T> implements OnDestroy {
110110
}
111111
}
112112

113-
static ngAcceptInputType_level: number | string | null | undefined;
113+
static ngAcceptInputType_level: NumberInput;
114114
}

0 commit comments

Comments
 (0)