1

If I have an array variable in TypeScript, should I use Array<type> or type[] to define that array? I have seen elsewhere that there is no syntactical difference, but if that is the case, then which one should I use in general and why?

Edit: Several people have suggested this question. While it confirms that the two are syntactically identical, it hasn't helped me determine which version to actually use in my programs. (I'm not sure if opinion-oriented questions are unpopular on SO, but that is essentially what I'm asking - which one do most people prefer to use, and is there a reason for that?)

GoldinGuy
  • 19
  • 1
  • 5
  • Dupe of https://stackoverflow.com/questions/36842158/arraytype-vs-type-in-typescript / opinion based – CertainPerformance Oct 15 '20 at 19:31
  • 1
    Does this answer your question? [Array VS Type\[\] in Typescript](https://stackoverflow.com/questions/36842158/arraytype-vs-type-in-typescript) – Andrey Tyukin Oct 15 '20 at 19:34
  • @CertainPerformance I saw that one, but it didn't help me figure out which one to use, only that they are identical. Are opinion-based questions not allowed on SO? I guess that is what I'm asking - if they are syntactically identical, is there one that most people prefer to use? – GoldinGuy Oct 15 '20 at 19:35
  • Different people prefer different styles. I don't know the statistics. No, opinion-based questions aren't allowed here. – CertainPerformance Oct 15 '20 at 19:36
  • Use a linter to encourage consistency. I use `type[]` mainly because that's the default linting rule. – Linda Paiste Oct 15 '20 at 19:43
  • If you ever need to compile React, the `< >` characters can be mistaken for JSX, so you might as well get used to writing `let myNumbers : number[]` – Kokodoko Oct 15 '20 at 19:44

0 Answers0