Skip to content

Commit

Permalink
fix: no more adding infinite boolean for function returning promise (#…
Browse files Browse the repository at this point in the history
…1481)

<!-- πŸ‘‹ Hi, thanks for sending a PR to TypeStat! πŸ’–.
Please fill out all fields below and make sure each item is true and [x]
checked.
Otherwise we may not be able to review your PR. -->

## PR Checklist

- [x] Addresses an existing open issue: fixes #1447 - I think it also
fixes #1284
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/TypeStat/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/TypeStat/blob/main/.github/CONTRIBUTING.md)
were taken 😹

## Overview

<!-- Description of what is changed and how the code change does that.
-->

It was this small change in the end??

Note, `async function navigateTo(): Promise<boolean> | boolean {` and
`async function navigateTo2(): Promise<boolean> | boolean {` are wrong.
Both should return only `Promise<boolean>`. I can remove those from the
test but I wanted to keep them to see, the difference.

Co-authored-by: rubiesonthesky <rubiesonthesky>
  • Loading branch information
rubiesonthesky authored Mar 30, 2024
1 parent 4177468 commit 9066333
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mutations/collecting/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { setSubtract } from "../../shared/sets.js";
const knownTypeFlagEquivalents = new Map([
[ts.TypeFlags.BigInt, ts.TypeFlags.BigIntLiteral],
[ts.TypeFlags.BigIntLiteral, ts.TypeFlags.BigInt],
[ts.TypeFlags.Boolean, ts.TypeFlags.BooleanLiteral],
[ts.TypeFlags.BooleanLiteral, ts.TypeFlags.Boolean],
[ts.TypeFlags.Number, ts.TypeFlags.NumberLiteral],
[ts.TypeFlags.NumberLiteral, ts.TypeFlags.Number],
[ts.TypeFlags.String, ts.TypeFlags.StringLiteral],
Expand Down
23 changes: 23 additions & 0 deletions test/cases/fixes/incompleteTypes/returnTypes/expected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,27 @@

return "";
};

async function navigateTo(): Promise<boolean> {
return await new Promise(() => "");
}

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

async function navigateTo(): Promise<boolean> | boolean {
return await navigateByUrl("");
}

async function navigateTo2(): Promise<boolean> | boolean {
const navigated = await navigateByUrl("");
return navigated;
}

async function returnSame(): Promise<boolean> {
return navigateByUrl("");
}

async function returnPromise(): Promise<string> {
return Promise.resolve("");
}
})();
23 changes: 23 additions & 0 deletions test/cases/fixes/incompleteTypes/returnTypes/original.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,27 @@

return "";
};

async function navigateTo(): Promise<boolean> {
return await new Promise(() => "");
}

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

async function navigateTo(): Promise<boolean> {
return await navigateByUrl("");
}

async function navigateTo2(): Promise<boolean> {
const navigated = await navigateByUrl("");
return navigated;
}

async function returnSame(): Promise<boolean> {
return navigateByUrl("");
}

async function returnPromise(): Promise<string> {
return Promise.resolve("");
}
})();

0 comments on commit 9066333

Please sign in to comment.