Loading topic
number | undefined. It also assumes you have met T[] and array literal inference in the earlier chapters. Here the question is what type you get when you read one element out of an array,5 min readmap, filter and reduce are where most array typing questions come up. This chapter covers how TypeScript types their callbacks and results, why filter does not narrow by default, and how type predicates fix that. It assumes you know JavaScript array methods, basic type 4 min readT[] and Array<T>. Here you will learn how readonly array types work, what they stop, and what they don't.5 min readT[] and Array<T>, inference of array literals, and readonly arrays.5 min readT[], you have seen tuple syntax such as [number, string], and you are comfortable with union types. Its goal is to give you a way to choose between the two types. It also covers what goes wrong when you choose badly.5 min read[number, string] and destructure them. It also assumes you know union types and how undefined behaves in TypeScript. By the end you will be able to write tuples whose length varies, predict the types TypeScript produces for them, and a4 min readas const turns an ordinary literal into a precise, immutable type. It assumes you know basic tuple types such as [number, string] and the readonly array modifier from the earlier chapters. It also assumes you know union types and litera4 min read[number, string], how to destructure them, and how readonly and as const work on arrays. It covers two places where a tuple's fixed length is weaker than it looks. The first is mutating methods like push. The second is reading an5 min readT extends unknown[]. It shows how a function's parameter list is itself a tuple type, and how to use that when you write wrappers, forwarders and argument 5 min read[...T, ...U], where T and U are generic. The compiler fills in the spread when it knows what T and U are. Before TypeScript 4.0, you could not express "these parameters, then those parameters" or "this tu5 min read