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

Expose TypeChecker.getAwaitedType for public api #59256

Closed
6 tasks done
yeonjuan opened this issue Jul 12, 2024 · 2 comments · Fixed by #59268
Closed
6 tasks done

Expose TypeChecker.getAwaitedType for public api #59256

yeonjuan opened this issue Jul 12, 2024 · 2 comments · Fixed by #59268
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@yeonjuan
Copy link
Contributor

yeonjuan commented Jul 12, 2024

🔍 Search Terms

getAwaitedType
public api

✅ Viability Checklist

⭐ Suggestion

TypeChecker.getAwaitedType is currently an Internal API. I propose to expose it as a public API.

/** @internal */
getAwaitedType(type: Type): Type | undefined;

📃 Motivating Example

In typescript-eslint, I'm working on improving the no-unsafe-return rule to check for types that returns Promise<any>.

To implement this feature, we need to get the awaited type of the promise. And it looks like this functionality is already implemented in TypeChecker getAwaitedType.
If getAwaitedType is provided as public, I think we can avoid duplicating the same logic in multiple tools that need similar functionality.

💻 Use Cases

  1. What do you want to use this for? Use it in the typescript-eslint.

  2. What shortcomings exist with current approaches?

  3. What workarounds are you using in the meantime? There is a way to get the first type argument of a Promise generic. But it doesn't catch some cases. (feat(eslint-plugin): [no-unsafe-return] check promise any typescript-eslint/typescript-eslint#8693 (comment))

@yeonjuan yeonjuan changed the title expose TypeChecker.getAwaitedType for public api Expose TypeChecker.getAwaitedType for public api Jul 12, 2024
@RyanCavanaugh
Copy link
Member

@rbuckton any objections? This seems fine to me

@jakebailey
Copy link
Member

I've wanted to do this for a while to simplify ts-eslint (but apparently forgot to make an issue).

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Jul 26, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants