-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug(cdk/coercion): coerceNumberProperty(thing, undefined)
has invalid implementation or signature
#29425
Comments
I'll work on this issue if no one working on it. |
@urugator it's not possible to set the fallback value as undefined as you can see on the implementation the default fallback value is 0. I suggest that you return a string as a work around like this. |
Yes and the issue states that the implementation or signature is not correct. |
It is correct that the return type of However as I said it is not possible to return A better recommendation would be to use |
export function coerceNumberProperty(value: any, fallbackValue: any) {
return _isNumberValue(value) ? Number(value) : arguments.length === 2 ? fallbackValue : 0;
}
// coerceNumberProperty('foo') === 0
// coerceNumberProperty('foo', undefined) === undefined Note that implementation signature is not visible from the outside, so this doesn't break the API, quite the opposite - the implementation is changed to match these 2 overload signatures, that are actually visible from the outside. |
Ohh okay I see, can you make the PR. |
Returns undefined when the fallback argument is undefined for cases where the value is not a number Fixes angular#29425
Returns undefined when the fallback argument is undefined for cases where the value is not a number Fixes angular#29425
@crisbeto Thank you for picking this up, but I think you forgot to remove the default value in argument function foo(x=0) {
console.log(arguments.length, x);
}
foo(); // 0 0
foo(undefined); // yields 1 0 but we want 1 undefined |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Is this a regression?
The previous version in which this bug was not present was
No response
Description
coerceNumberProperty(thing, undefined)
works the same way ascoerceNumberProperty(thing)
, so it yields0
if thething
isn't coercible to number. This is quite unexpected, because:coerceNumberProperty(thing, undefined)
returnsnumber | undefined
, even though the implementation always yieldsnumber
.Reproduction
StackBlitz link:
Steps to reproduce:
1.
2.
Expected Behavior
Fallback argument should be respected even for
undefined
.Actual Behavior
undefined
isn't respected as a fallback.Environment
The text was updated successfully, but these errors were encountered: