8000 Overloaded function with at least one generic overload can be assigned to any function with at least the same number of parameters · Issue #50050 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

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
@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

    0