TypeScript - [string] vs string []

In typescript, what is right?

[string] vs string []

public searchOption: [string] = ['date'];
public searchOption: string[] = ['date'];
+6
source share
3 answers

The first is tuple , and the second is an array of strings.

You can do this with tuples:

let searchOption: [string, number] = ['date', 22];
+3
source

If all you are going to do is make an array of strings, they both seem to behave the same. However, the second is the one you should use.

First, so you can make Tuples like this.

let searchOption: [string, number] = ['date', 1];
+2
source

Source: https://habr.com/ru/post/1016311/


All Articles