Skip to content

Commit

Permalink
fix(ts): Immutable<T> / read-only arrays in TS 3.4+
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Apr 17, 2019
1 parent a5ce2ae commit 2c27133
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/immer.d.ts
Expand Up @@ -53,6 +53,10 @@ export type Produced<Base, Return> = Return extends void
? Promise<Result extends void ? Base : FromNothing<Result>>
: FromNothing<Return>

type ImmutableArray<T extends ReadonlyArray<any>> = {
[P in Extract<keyof T, number>]: ReadonlyArray<Immutable<T[number]>>
}[Extract<keyof T, number>]

type ImmutableTuple<T extends ReadonlyArray<any>> = {
readonly [P in keyof T]: Immutable<T[P]>
}
Expand All @@ -63,7 +67,7 @@ export type Immutable<T> = T extends object
? T
: T extends ReadonlyArray<any>
? Array<T[number]> extends T
? {[P in keyof T]: ReadonlyArray<Immutable<T[number]>>}[keyof T]
? ImmutableArray<T>
: ImmutableTuple<T>
: {readonly [P in keyof T]: Immutable<T[P]>}
: T
Expand Down

0 comments on commit 2c27133

Please sign in to comment.