Skip to content

Commit

Permalink
fix(cdk/coercion): Return undefined when the fallback value is undefi…
Browse files Browse the repository at this point in the history
…ned (#29491)

Returns undefined when the fallback argument is undefined
for cases where the value is not a number

Fixes #29425
  • Loading branch information
GiftLanga authored Jul 29, 2024
1 parent 97749b1 commit c9078d1
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 c9078d1

Please sign in to comment.