Using const assertion, one can nicely narrow an object/array literal's type to its elements.
e.g.
const arr = [
[5, "hello"],
[5, "bye"],
] as const;
type T = typeof arr; // type T = readonly [readonly [5, "hello"], readonly [5, "bye"]]
(Without as const, T would be type T = (string | number)[][], which is very wide and sometimes unwanted.)
Now, the problem is that as a result of that as const the array becomes readonly as well, while I just it to have a narrowed type. So, it cannot be passed to the following function.
function fiveLover(pairs: [5, string][]): void {
pairs.forEach((p) => console.log(p[1]));
}
fiveLover(arr); // Error
And the Error is:
Argument of type
'readonly [readonly [5, "hello"], readonly [5, "bye"]]'is not assignable to parameter of type'[5, string][]'. The type'readonly [readonly [5, "hello"], readonly [5, "bye"]]'is'readonly'and cannot be assigned to the mutable type'[5, string][]'.(2345)
Question
How can I narrow the type, without getting the unwanted readonly attribute? (Preferably at the object/array creation time.)