#Keep array as a tuple
13 messages · Page 1 of 1 (latest)
Preview:```ts
function f<Cols extends any[]>(cols: Cols) {}
f(["hi", "hello"])
// Cols is string[], not ["hi", "hello"]```
You can choose specific lines to embed by selecting them before copying the link.
Here is why I need it, I have this other type that takes in an object and an array of keys of the object and returns an array (with the same order as the keys) of the types of each key. It works when I use it as a type and I pass in a tuple, but when I use it in a function, the function converts the type to an array of all of the types in the array.
function f<const Cols extends any[]>(cols: Cols) {
tf, since when does this exist????
Okay another question, how do I write this in JSDoc?😅