Microsoft/TypeScript

Bizarre circular type false positive

Open

#48.708 geöffnet am 14. Apr. 2022

Auf GitHub ansehen
 (7 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: check: Type CircularityHelp Wanted

Repository-Metriken

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

Beschreibung

Bug Report

🔎 Search Terms

implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)

🕗 Version & Regression Information

This changed between versions 4.6.2 and 4.7.0-beta

⏯ Playground Link

Playground link with relevant code

💻 Code

type Wrapper = {
    data: number | null;
};

function example(wrapper: Wrapper) {
    // The error goes away if this line is removed and `null` is removed from the type
    if (wrapper.data === null) return;

    // The error goes away if the loop body is inlined o_O
    for (const _ of []) {
        const d = wrapper.data;
        //    ^ 'd' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

        // The error goes away without these lines o_O
        const t = d;
        const list = [0];
        if (list[t]) {}
    }
}

🙁 Actual behavior

Error: implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer

🙂 Expected behavior

No error

Contributor Guide