The Wayback Machine - https://web.archive.org/web/20210206043855/https://github.com/microsoft/TypeScript/issues/42529
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect TS7022 error in loop #42529

Open
mysticatea opened this issue Jan 28, 2021 · 1 comment
Open

Incorrect TS7022 error in loop #42529

mysticatea opened this issue Jan 28, 2021 · 1 comment

Comments

@mysticatea
Copy link

@mysticatea mysticatea commented Jan 28, 2021

Bug Report

Tsc threw TS7022 error on the place that is not any type.

        const group = await fetchGroup(nextId); // (id: string) => Promise<Group>
        //    ^^^^^ 'group' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. (7022)

🔎 Search Terms

  • 7022

#33191 and #39183 are maybe related. But in this case, the return type of fetchGroup() does not depend on parameters; that always Promise<Group> explicitly. Also, the type of nextId is always string at the line.

🕗 Version & Regression Information

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

(3.3.3 ... 4.2.0-dev.20210127)

Playground Link

Playground link with relevant code

💻 Code

interface Group {
    parentId: string | undefined
    //...
}

declare function fetchGroup(id: string): Promise<Group>

async function fetchAncestorGroups(leafId: string): Promise<Group[]> {
    const groups: Group[] = [];
    let nextId: string | undefined = leafId;

    while (nextId) {
        const group = await fetchGroup(nextId);
        //    ^^^^^ 'group' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. (7022)
        groups.push(group);
        nextId = group.parentId;
    }
    return groups.reverse();
}

🙁 Actual behavior

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

🙂 Expected behavior

No errors.

@RyanCavanaugh
Copy link
Member

@RyanCavanaugh RyanCavanaugh commented Jan 28, 2021

This really is a circularity; the fact that we can higher-order-reason our way out of it doesn't make it not a circularity. The core checking algorithm doesn't have mechanisms in place that would allow this to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants