pacote
pacote copied to clipboard
Immutable<T> incorrectly changes tuples to ReadonlyArray
Immutable incorrectly changes tuples to ReadonlyArray. For example:
import { Immutable } from '@pacote/immutable'
type ImmutableTuple = Immutable<[number, string]>
// expected => Readonly<[number, string]>
// actual => ReadonlyArray<number | string>
const test: ImmutableTuple = ['string', 1] // this should be failing compilation
The correct behaviour is for Immutable<[number, string]> to become Readonly<[number, string]>.
The way tuples are implemented in typescript, I don't believe there is a way to do this except for declaring an internal type for each of the different arity tuples explicitly and then use a union type for the exported type. Even so I don't know if at the call site the compiler can differentiate the cases correctly.