Skip to content

no-useless-undefined with strictNullCheck and <T | undefined> #2899

@castral

Description

@castral

When you have strictNullChecks enabled in tsconfig, you are explicitly required to pass undefined as a value to a function when it is not optional and a generic or the parameter type for that argument is a union with undefined, for example:

function test<T extends object | undefined>(arg: T): void {

}

test({}); // fine
test(undefined); // fine, but eslint complains on rule unicorn/no-useless-undefined
test(); // not fine, compiler throws TS2554: Expected 1 arguments, but got 0

I ran into this issue with the unicorn/no-useless-undefined rule and worked around it by setting checkArguments: false but it seems like an incorrect implementation to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions