Closed
Description
What happened
The TypeScript signature of methods like first
, last
, etc that take a notSetValue
is:
first<NSV>(notSetValue?: NSV): V | NSV;
In TypeScript (at least in 4.1.2
) if no argument is passed, NSV
becomes unknown
, not undefined
as documented.
Possible fix:
first<NSV = undefined>(notSetValue?: NSV): V | NSV;
I found this PR but it never got merged: #1653. I think = undefined
is less verbose as it doesn't create a new overload. If going with this overload approach, the correct declaration would be (instead of the one in the PR):
first(): V | undefined;
first<NSV>(notSetValue?: NSV): V | NSV;
I'd create a PR but didn't know how you wanted to handle #1653.
Note that other methods that accept a notSetValue
argument probably suffer from the same issue.
Thank you.