Microsoft/TypeScript

Only `null` and `undefined` included in later overloads during inference between overloads

Open

#47.586 geöffnet am 25. Jan. 2022

Auf GitHub ansehen
 (2 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Help WantedNeeds Investigation

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

Bug Report

🔎 Search Terms

overload null undefined

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I wrote the FAQ

⏯ Playground Link

Playground link with relevant code

💻 Code

This is a bit over-reduced but it's still weird

declare function callIt<T>(func: {
    (): T;
    (): T;
}): T;

declare function overloaded(): string;
declare function overloaded(): number | null;

// m: string | null. Where'd number go?
const m = callIt(overloaded);

🙁 Actual behavior

m: string | null

🙂 Expected behavior

m: string | number | null

This feels intentional since it only null and undefined make it out of the second signature, but I can't find where we do this or what the motivation behind it is.

Contributor Guide