pacote icon indicating copy to clipboard operation
pacote copied to clipboard

Immutable<T> incorrectly changes tuples to ReadonlyArray

Open goblindegook opened this issue 7 years ago • 1 comments

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]>.

goblindegook avatar Jan 11 '19 01:01 goblindegook

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.

teves-castro avatar Jan 11 '19 08:01 teves-castro