Typing collections in Typescript
How are collections typed in Typescript? Primitives are fairly easy to type - we have seen this while discussing Typescript and its types. const num: number = 0; const msg: string = "hello"; We have seen examples of typed arrays in the same post, but how about all the other collections? How far down the typed rabbit hole are you willing to go? Arrays There are two useful notations - pick one, or both. let num: number[] = [1, 2, 3]; const numToo: Array<number> = [1, 2, 3]; Tuples Tuples, unlike arrays, have fixed number of elements. In Typescript, we just go about typing all of them. ...