From 2c7691777915e1fd051fd22458980e63fa15958d Mon Sep 17 00:00:00 2001 From: Gift Langa <46772946+GiftLanga@users.noreply.github.com> Date: Mon, 29 Jul 2024 17:38:07 +0200 Subject: [PATCH] fix(cdk/coercion): Return undefined when the fallback value is undefined (#29491) Returns undefined when the fallback argument is undefined for cases where the value is not a number Fixes #29425 (cherry picked from commit c9078d1d1ada5d35a023e64c34d4f953adeec415) --- src/cdk/coercion/number-property.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cdk/coercion/number-property.ts b/src/cdk/coercion/number-property.ts index 2452ab2f15a8..50b5ff8d0841 100644 --- a/src/cdk/coercion/number-property.ts +++ b/src/cdk/coercion/number-property.ts @@ -16,7 +16,10 @@ export type NumberInput = string | number | null | undefined; export function coerceNumberProperty(value: any): number; export function coerceNumberProperty(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; } /**