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.
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:
[x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
[x] This wouldn't change the runtime behavior of existing JavaScript code
[x] This could be implemented without emitting different JS based on the types of the expressions
[x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
Search Terms
Suggestion
expose
getPromisedTypeOfPromise
in theTypeChecker
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
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 annotatey
with: number
.Checklist
My suggestion meets these guidelines: