Microsoft/TypeScript

Bizarre circular type false positive

Open

#48,708 opened on 2022幎4月14日

GitHub で芋る
 (7 comments) (0 reactions) (0 assignees)TypeScript (6,726 forks)batch import
BugDomain: check: Type CircularityHelp Wanted

Repository metrics

Stars
 (48,455 stars)
PR merge metrics
 (平均マヌゞ 6d 17h) (30d で 9 merged PRs)

説明

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

コントリビュヌタヌガむド