Skip to content

TypeScript 4.1.2 resolves notSetValue to unknown #1806

Closed
@pedro-pedrosa

Description

@pedro-pedrosa

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions