You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
What do you want to use this for? Use it in the typescript-eslint.
🔍 Search Terms
getAwaitedType
public api
✅ Viability Checklist
⭐ Suggestion
TypeChecker.getAwaitedTypeis currently an Internal API. I propose to expose it as a public API.TypeScript/src/compiler/types.ts
Lines 4971 to 4972 in 4641004
📃 Motivating Example
In
typescript-eslint, I'm working on improving theno-unsafe-returnrule to check for types that returnsPromise<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
What do you want to use this for? Use it in the typescript-eslint.
What shortcomings exist with current approaches?
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))