Skip to content

Typescript pitfalls

MatthewThe edited this page Jan 19, 2023 · 2 revisions

Typescript gets confused between tuples and arrays, e.g. it often infers number[] instead of [number, number].

You can fix this by explicitly casting the tuple e.g. [1,2] as [number, number]

Note that this also happens for mixed type tuples, e.g. [1, "abc"] is inferred as [number | string][] instead of [number, string].

Clone this wiki locally