

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Arrays
incomplete
2: Type Parameters
incomplete
3: Heterogeneous Arrays
incomplete
4: Rest Parameters
incomplete
5: Evolving Any
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
TypeScript offers an alternative way to declare arrays using type parameter syntax: Array<T>, which, for now, just know that it's basically the same as the "normal" T[] syntax. You'll see both versions in the wild.
These function declarations are the same:
// Using bracket notation
function assignLightsaberColors(name: string, colors: string[]): void {
// ...
}
// Using generic type parameter syntax
function assignLightsaberColors(name: string, colors: Array<string>): void {
// ...
}
You can also use either syntax when declaring variables:
const colors: string[] = [
"blue",
"green",
"purple",
"red",
"orange",
"white",
"darksaber",
];
const midichlorianCounts: Array<number> = [
1000, 5000, 12000, 20000, 27000, 40000,
];
Later, when we talk about generics, it will make a bit more sense why you might use Array<T> over T[] - and the answer is mostly because it will feel consistent with other generic types.
In the common case, I prefer number[] over Array<number>. It looks like an array (square brackets) and it's a bit faster to type.