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

Lines changed: 3 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 {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

Lines changed: 3 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 {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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 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 {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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 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 {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
}

0 commit comments

Comments
 (0)