as const
Last updated
Last updated
We use as const
to type assert. And this works great if :
Theoretically I could return
But those are a bit too verbose. So we could assert (aka just telling ts directly) that we know that this array won't change.
The return type of this function is a
MUTABLE
array and we want to tell TS that it's actuallyIMMUTABLE
and therefore you can set the array's type as NON-widening. And Arrays and Objects arereadonly
so they never are able to change their order
Resource: