Skip to content

Commit ff2107f

Browse files
committed
refactor: eliminate 'any' type in cdk coercion utilities
1 parent b627aef commit ff2107f

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

goldens/cdk/coercion/index.api.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ export function coerceArray<T>(value: T | T[]): T[];
1616
export function coerceArray<T>(value: T | readonly T[]): readonly T[];
1717

1818
// @public
19-
export function coerceBooleanProperty(value: any): boolean;
19+
export function coerceBooleanProperty(value: unknown): boolean;
2020

2121
// @public
22-
export function coerceCssPixelValue(value: any): string;
22+
export function coerceCssPixelValue(value: unknown): string;
2323

2424
// @public
2525
export function coerceElement<T>(elementOrRef: ElementRef<T> | T): T;
2626

2727
// @public
28-
export function coerceNumberProperty(value: any): number;
28+
export function coerceNumberProperty(value: unknown): number;
2929

3030
// @public (undocumented)
31-
export function coerceNumberProperty<D>(value: any, fallback: D): number | D;
31+
export function coerceNumberProperty<D>(value: unknown, fallback: D): number | D;
3232

3333
// @public
34-
export function coerceStringArray(value: any, separator?: string | RegExp): string[];
34+
export function coerceStringArray(value: unknown, separator?: string | RegExp): string[];
3535

3636
// @public
37-
export function _isNumberValue(value: any): boolean;
37+
export function _isNumberValue(value: unknown): boolean;
3838

3939
// @public
4040
export type NumberInput = string | number | null | undefined;

src/cdk/coercion/boolean-property.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
export type BooleanInput = string | boolean | null | undefined;
1414

1515
/** Coerces a data-bound value (typically a string) to a boolean. */
16-
export function coerceBooleanProperty(value: any): boolean {
17-
return value != null && `${value}` !== 'false';
16+
export function coerceBooleanProperty(value: unknown): boolean {
17+
return value != null && String(value) !== 'false';
1818
}

src/cdk/coercion/css-pixel-value.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88

99
/** Coerces a value to a CSS pixel value. */
10-
export function coerceCssPixelValue(value: any): string {
10+
export function coerceCssPixelValue(value: unknown): string {
1111
if (value == null) {
1212
return '';
1313
}
1414

15-
return typeof value === 'string' ? value : `${value}px`;
15+
return typeof value === 'string' ? value : `${String(value)}px`;
1616
}

src/cdk/coercion/number-property.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
export type NumberInput = string | number | null | undefined;
1414

1515
/** Coerces a data-bound value (typically a string) to a number. */
16-
export function coerceNumberProperty(value: any): number;
17-
export function coerceNumberProperty<D>(value: any, fallback: D): number | D;
18-
export function coerceNumberProperty(value: any, fallbackValue = 0) {
16+
export function coerceNumberProperty(value: unknown): number;
17+
export function coerceNumberProperty<D>(value: unknown, fallback: D): number | D;
18+
export function coerceNumberProperty(value: unknown, fallbackValue = 0) {
1919
if (_isNumberValue(value)) {
2020
return Number(value);
2121
}
@@ -26,9 +26,9 @@ export function coerceNumberProperty(value: any, fallbackValue = 0) {
2626
* Whether the provided value is considered a number.
2727
* @docs-private
2828
*/
29-
export function _isNumberValue(value: any): boolean {
29+
export function _isNumberValue(value: unknown): boolean {
3030
// parseFloat(value) handles most of the cases we're interested in (it treats null, empty string,
3131
// and other non-number values as NaN, where Number just uses 0) but it considers the string
3232
// '123hello' to be a valid number. Therefore we also check if Number(value) is NaN.
33-
return !isNaN(parseFloat(value as any)) && !isNaN(Number(value));
33+
return !isNaN(parseFloat(String(value))) && !isNaN(Number(value));
3434
}

src/cdk/coercion/string-array.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
* @param value the value to coerce into an array of strings
2424
* @param separator split-separator if value isn't an array
2525
*/
26-
export function coerceStringArray(value: any, separator: string | RegExp = /\s+/): string[] {
26+
export function coerceStringArray(value: unknown, separator: string | RegExp = /\s+/): string[] {
2727
const result = [];
2828

2929
if (value != null) {
30-
const sourceValues = Array.isArray(value) ? value : `${value}`.split(separator);
30+
const sourceValues = Array.isArray(value) ? value : String(value).split(separator);
3131
for (const sourceValue of sourceValues) {
32-
const trimmedString = `${sourceValue}`.trim();
32+
const trimmedString = String(sourceValue).trim();
3333
if (trimmedString) {
3434
result.push(trimmedString);
3535
}

0 commit comments

Comments
 (0)