Skip to content

Return type duplicate infinite amount: | boolean #1447

@rubiesonthesky

Description

@rubiesonthesky

🐛 Bug Report

  • TypeStat version: 0.7.3
  • TypeScript version: 4.9.5
  • Node version: 20.11

Actual Behavior

declare function navigateByUrl(url: string): Promise<boolean>;

export class exampleDirective {
  async navigateTo(id: number): Promise<boolean> | boolean | boolean | boolean | boolean | boolean {
    return await navigateByUrl(`/page/${id}`);
  }
}

Expected Behavior

There is no need to change this the return type. This is async function and Promise<boolean> should cover that. But also, it should not add boolean infinite amount to return types union.

declare function navigateByUrl(url: string): Promise<boolean>;

export class exampleDirective {
  async navigateTo(id: number): Promise<boolean> {
    return await navigateByUrl(`/page/${id}`);
  }
}

Reproduction

Original code

declare function navigateByUrl(url: string): Promise<boolean>;

export class exampleDirective {
  async navigateTo(id: number): Promise<boolean> {
    return await navigateByUrl(`/page/${id}`);
  }
}

I cloned this repo and added this test case to test/cases/fixes/incompleteTypes/returnTypes/original.ts file, and I can see same behavior there.

    function navigateByUrl(url: string): Promise<boolean>;

    async function navigateTo(id: number): Promise<boolean> {
        return await navigateByUrl(`/page/${id}`);
    }

After using command yarn run test:mutation --accept, I see this in excepted.ts and actual.ts:

    function navigateByUrl(url: string): Promise<boolean>;

    async function navigateTo(id: number): Promise<boolean> | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean | boolean {
        return await navigateByUrl(`/page/${id}`);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: fixersAround how TypeStat fixes code.status: accepting prsPlease, send a pull request to resolve this! 🙏type: bugSomething isn't working :( 🐛

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions