Preserve comments with object destructuring assignment

Ouverte
#32,392 11 commentaires 9 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
48/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Calme
Stack technique
typescript
Domaine
compilers

Piste de recherche

Reproduisez le comportement dans le TypeScript Playground lié, en comparant les info-bulles au survol pour les propriétés auxquelles on accède directement et les variables introduites par object destructuring. Suivez le chemin de language-service/type-checking qui résout les commentaires des bindings déstructurés ; le travail est terminé lorsque les commentaires des propriétés déclarées apparaissent pour x, y et les paramètres de fonction déstructurés, sans modifier la sortie à l’exécution.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Awaiting More Feedback Suggestion

Search Terms

object destructuring assignment, comment

Suggestion

interface MyInterface {
    /**
     * I am x
     */
    x : number;
    /**
     * I am y
     */
    y : number;
}
declare const myInterface : MyInterface;
const {x, y} = myInterface;

/**
 * Expected tooltip to have comment,
 * > I am x
 * 
 * Actual: No comment
 */
x;
/**
 * Expected tooltip to have comment,
 * > I am y
 * 
 * Actual: No comment
 */
y;

/**
 * Expected tooltip to have comment,
 * > I am x
 * 
 * Actual:
 * Tooltip has comment,
 * > I am x
 */
myInterface.x;

/**
 * Expected tooltip to have comment,
 * > I am y
 * 
 * Actual:
 * Tooltip has comment,
 * > I am y
 */
myInterface.y;

/**
 * I am z
 */
const z = 1;

/**
 * Expected tooltip to have comment,
 * > I am z
 * 
 * Actual:
 * Tooltip has comment,
 * > I am z
 */
z;

Playground

Use Cases

I came across this idea after writing code like this,

function foo (
  {
    somePropertyA,
    somePropertyB,
    somePropertyC,
  } : SomeObject
) {
  /* Use these properties */
}

And I was hazy on the details of what each property was for.
So, I hovered my cursor over the variables somePropertyA, somePropertyB, somePropertyC and noticed there were no comments.

I had to go to the declaration of somePropertyA, somePropertyB, somePropertyC and look at each property individually.


At the moment, the way to get comments is to just do,

function foo (
  o : SomeObject
) {
  /* Use these properties */
}

Then the tooltip for o.somePropertyA, o.somePropertyB, o.somePropertyC will have comments

Examples

See above suggestion

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.
Langage dominant
Go
Étoiles
111k
Forks
14.4k
Merge moyen
1 j 19 h
PR mergées (30 j)
117

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.

Autres issues de microsoft/TypeScript

Toutes les issues de microsoft/TypeScript

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

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