Skip to content

Commit

Permalink
fix(cdk/coercion): Return undefined when the fallback value is undefined
Browse files Browse the repository at this point in the history
Returns undefined when the fallback argument is undefined
for cases where the value is not a number

Fixes #29425
  • Loading branch information
GiftLanga committed Jul 26, 2024
1 parent c4f033c commit 61e06c5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cdk/coercion/number-property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export type NumberInput = string | number | null | undefined;
export function coerceNumberProperty(value: any): number;
export function coerceNumberProperty<D>(value: any, fallback: D): number | D;
export function coerceNumberProperty(value: any, fallbackValue = 0) {
return _isNumberValue(value) ? Number(value) : fallbackValue;
if (_isNumberValue(value)) {
return Number(value);
}
return arguments.length === 2 ? fallbackValue : 0;
}

/**
Expand Down

0 comments on commit 61e06c5

Please sign in to comment.