microsoft / microsoft/TypeScript

Feature Request: expose getPromisedTypeOfPromise

Ouverte
#30,774 3 commentaires 0 réactions 1 personne assignée Voir sur GitHub

@rbuckton y travaille déjà.

Depuis le 10/4/2019.

Domain: API Needs Investigation
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.