// literal let fruits: string[] = ['Apple', 'Orange', 'Banana']; // generics let fruits: Array<string> = ['Apple', 'Orange', 'Banana'];
[string]
vs string[]
[string]
is a tuplestring[]
is an array of stringsTuple types allow you to express an array with a fixed number of elements whose types are known, but need not be the same
// Declare a tuple type let x: [string, number]; // Initialize it x = ["hello", 10]; // OK // Initialize it incorrectly x = [10, "hello"]; // Error // Error: Tuple type '[string, number]' of length '2' has no element at index '3'. x[3] = "world";