Skip to content

Overloaded function with at least one generic overload can be assigned to any function with at least the same number of parametersΒ #50050

Open
@otonashixav

Description

@otonashixav

Bug Report

πŸ”Ž Search Terms

overload, generic, function

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about overloads and generics.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// only overloaded
function a(value: string): void;
function a(value: number): void;
function a(value: string | number) { value.toString() };

// only generic
function b<T extends number>(value: T): void { value.toString() };

// overloaded with generic
function c(value: string): void;
function c<T extends number>(value: T): void;
function c(value: string | number) { value.toString() };

// these are errors as expected
() => {
    let d: (value: unknown) => void = a;
    let e: (value: unknown) => void = b;
    c(null);
}

// this should be an error
let f: (value: unknown) => void = c;
f(null);

πŸ™ Actual behavior

In the example above I call f(null) and cause a runtime error, however typescript doesn't warn me about it.

πŸ™‚ Expected behavior

c should not be assignable to (value: unknown) => void.

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions