Skip to content

Feature Request: expose getPromisedTypeOfPromise #30774

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

Open
5 tasks done
maclockard opened this issue Apr 5, 2019 · 3 comments
Open
5 tasks done

Feature Request: expose getPromisedTypeOfPromise #30774

maclockard opened this issue Apr 5, 2019 · 3 comments
Assignees
Labels
API Relates to the public API for TypeScript Needs Investigation This issue needs a team member to investigate its status.

Comments

@maclockard
Copy link

Search Terms

  • getPromisedTypeOfPromise
  • detect Promise

Suggestion

expose getPromisedTypeOfPromise in the TypeChecker API.

Use Cases

Writing lint rules with typechecking involving promises. One example is one checking the result of a yield in a generator. Since yields inside generators are not typed, being able to use linting to check types are properly annotated can be powerful.

Examples

// source code
const myAsyncFunc = async (num: number) => num;

function* gen() {
   const y = yield call(myFunc);
}

call is a redux saga effect that has an API contract of calling a passed function and awaiting if it is a promise. Given this contract, its possible to write a lint rule instructing a consumer to annotate y with : number.

// lint rule
...
let returnType = appliedFunctionType.getCallSignatures()[0].getReturnType();

if(// is promise) {
  returnType = typeChecker.getPromisedTypeOfPromise(returnType);
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added API Relates to the public API for TypeScript Needs Investigation This issue needs a team member to investigate its status. labels Apr 10, 2019
@RyanCavanaugh
Copy link
Member

@rbuckton thoughts?

@d2201
Copy link

d2201 commented Jul 4, 2021

any updates on this feature request?

@aleclarson
Copy link

aleclarson commented Oct 6, 2024

This would be so useful.

Is there an easy workaround for now? (that doesn't involve as any 😉 )

edit: Oh, it seems that #59268 exposed getAwaitedType, so this issue can be closed, or no?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

5 participants