microsoft / microsoft/TypeScript

Feature Request: Provide an option to configure the presentation of Arrays

Ouverte
#44,715 1 commentaire 9 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Awaiting More Feedback Suggestion
Langage dominant
Go
Étoiles
111k
Forks
14.4k
Merge moyen
1 j 19 h
PR mergées (30 j)
117

Description

Suggestion

Provide an option to configure the presentation of Arrays.

🔍 Search Terms

This suggestion is hard to search for ☹️

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behaviour 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

I would like to see an option that will allow for altering the presentation of Arrays.

📃 Motivating Example

When reading through type errors or hovering over source code in VS Code, I find it hard to easily distinguish between Arrays, Tuples, Arrays of Tuples, Tuples with Arrays in them etc.

I personally use linting rules so that I know that when I see a [ or ] in my source code, I am explicitly dealing with a Tuple.

For example, I find Array<[Array<T>]> far easier to quickly parse than [T[]][]. This may simply be attributed to my bias of writing code in the generic form. Though, this gets worse with increased levels of nesting.

🎨 Prior art

The tslint rule array-type can be used to enforce using the generic form of Array<T>. Secondarily, this rule was also ported as the @typescript/eslint rule array-type.

💻 Use Cases

I find hovering over my own code and seeing it presented differently a bit frustrating. Consider the following playground screenshot:

Hover

In addition toarray-types options of "array", "generic", "array-simple", a fourth option of "preserve" could be added which would address the screenshot above.

I would like to suggest the following option:

Flag Type Default value
--arrayType "array" | "generic" | "array-simple" | "preserve" "preserve"

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.

Piste de recherche

Commencez par le playground TypeScript lié et l’exemple de survol de VS Code afin de comparer la présentation actuelle des tableaux imbriqués et des tuples. Examinez les valeurs --arrayType demandées et définissez comme terminé le fait de préserver ou de formater de manière cohérente la syntaxe des tableaux dans les erreurs de type et les affichages au survol, sans modifier le JavaScript généré.

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

Évaluation

Stack technique
typescript
Domaine
compilers
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

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