Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 tasks done
whitneyit opened this issue Jun 24, 2021 · 1 comment
Open
5 tasks done
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@whitneyit
Copy link
Contributor

whitneyit commented Jun 24, 2021

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"
@Jamesernator
Copy link

I'm definitely plus-one on this, although for code authored by the user I think it probably doesn't even need configuration, just show the type as authored rather than regenerating a presentation. i.e. If I write string[] show string[], if I write Array<string> show Array<string>.

Obviously this doesn't neccessarily work for library code, so an option would probably be necessary for that.

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants