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

Closed
mysticatea opened this issue Jan 28, 2021 · 3 comments
Closed

Incorrect TS7022 error in loop #42529

mysticatea opened this issue Jan 28, 2021 · 3 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@mysticatea
Copy link

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 RyanCavanaugh added Working as Intended The behavior described is the intended behavior; this is not a bug Design Limitation Constraints of the existing architecture prevent this from being fixed and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Jan 28, 2021
@RyanCavanaugh
Copy link
Member

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.

@disjukr
Copy link

disjukr commented Jun 2, 2021

#30308 also related

@JoostK
Copy link
Contributor

JoostK commented Feb 28, 2024

This is no longer reported as an error since TS 5.0, unlike this scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

4 participants