microsoft / microsoft/TypeScript
Optional arguments in JSDoc types may be moved to TypeScript types quickfix
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
TypeScript Version: 3.4.3
80004jsdoc quickfix optional
Code
With Closure Compiler, you mark a function parameter optional by adding an = after its type (reference):
/**
* @param a {string} Base string.
* @param b {string=} Optional string to add
* @return {string}
*/
function foo(a, b) {
if (b) return a + b;
return a;
}
TypeScript offers a quickfix to convert these jsdoc annotations to TypeScript types:

Expected behavior:
The b parameter should be optional:
/**
* @param a {string} Base string.
* @param b {string=} Optional string to add
* @return {string}
*/
function foo(a: string, b?: string): string {
if (b) return a + b;
return a;
}
Actual behavior:
The b parameter is required but has type string | optional:
/**
* @param a {string} Base string.
* @param b {string=} Optional string to add
* @return {string}
*/
function foo(a: string, b: string | undefined): string {
if (b) return a + b;
return a;
}
This means that all calls of the function which don't specify b will be flagged as errors.
Playground Link: link, though quickfixes are not available there
Related Issues:
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire le quickfix des types JSDoc-to-TypeScript avec la fonction foo fournie et comparez le type de paramètre généré avec le paramètre optionnel attendu. Suivez le point d’entrée du quickfix et ajoutez une couverture de régression montrant que les appels omettant b sont acceptés, tandis que le type de retour généré reste string.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript, typescript
- Domaine
- compilers, tooling
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 42/100