

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
If you can do it in JavaScript, you can model it in TypeScript. It might not always be pretty... but in this case it is!
In languages like Go, you can't have an array that contains different types - at least not without using something a bit more complex like a struct or an interface. But in TypeScript, we can just union the types!
// TypeScript infers the type as (string | number)[]
let lightsaberStyles = [1, 2, "double", "shoto"];
function describe(style: string | number): void {
console.log(`Wield ${style} lightsaber`);
}
lightsaberStyles.forEach(describe);
// Wield 1 lightsaber
// Wield 2 lightsaber
// Wield double lightsaber
// Wield shoto lightsaber
Just use a pipe | to create union types. Easy!
Complete the interpolateComment function. It accepts three parameters:
id numbercomment stringcomments array of strings and numbersIt should find the first element in the comments array that equals id and replace just that element with the new comment.
Your function should mutate the comments array directly, rather than returning a new array.