You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be possible to update the typing of max([0, someNumberVariable]) such that it returns number?
Given this Typescript code
max([0,someNumberVariable])
I would expect the type to be a number.
Instead the type is number | undefined
So in practice, I need to write the function as
max([0,someNumberVariable])asnumber
I've done weirder things with TypeScript in the past, so it seems likely that this would be possible, but I can't even find the definition of max in the Lodash repo, so I might not be correct.
The text was updated successfully, but these errors were encountered:
type NonEmptyArray<T> = [T, ...T[]];
function max<T>(array: NonEmptyArray<T>): T;
function max<T>(array: T[]): T | undefined;
function max<T>(array: T[]): T | undefined {
return (array && array.length)
? baseExtremum(array, identity, baseGt)
: undefined;
}
const foo = max([4, 2, 8, 6]) // number
const bar = max([]) // undefined
const baz = max([[]]) // never[] - I don't even know what that means ...
Context
Would it be possible to update the typing of
max([0, someNumberVariable])
such that it returns number?Given this Typescript code
I would expect the type to be a number.
Instead the type is
number | undefined
So in practice, I need to write the function as
I've done weirder things with TypeScript in the past, so it seems likely that this would be possible, but I can't even find the definition of
max
in the Lodash repo, so I might not be correct.The text was updated successfully, but these errors were encountered: