Skip to content
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

TypeScript 4.1.2 resolves notSetValue to unknown #1806

Closed
pedro-pedrosa opened this issue Jan 26, 2021 · 1 comment
Closed

TypeScript 4.1.2 resolves notSetValue to unknown #1806

pedro-pedrosa opened this issue Jan 26, 2021 · 1 comment

Comments

@pedro-pedrosa
Copy link

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.

@Methuselah96
Copy link
Contributor

This has been resolved in #1676, but hasn't been released yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants