If I want to define a tuple or constant object shape, I'd use as const
. E.g.:
const arr = [{ a: 1 }] as const;
/* readonly [{
readonly a: 1;
}] */
However, I don't want readonly
because I'd get a lot of The type 'readonly ...' is 'readonly' and cannot be assigned to the mutable type '...'
I defined a "Mutable" generic:
type Mutable<T> = {
-readonly [K in keyof T]: Mutable<T[K]>;
}
type Arr = Mutable<typeof arr>;
/* [Mutable<{
readonly a: 1;
}>] */
However, TS doesn't recursively apply Mutable
in VS Code's type preview. In other words, I want VS Code's type preview to show:
/* [{
a: 1;
}] */
I don't think it's possible for VS Code to recursively evaluate Mutable
, since it could be too slow.
Is there something like as const
, but without adding readonly
?