Skip to content

Expose TypeChecker.getAwaitedType for public api #59256

Closed
@yeonjuan

Description

@yeonjuan

🔍 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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WantedYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions