Skip to content

Commit 7497f73

Browse files
author
ben.durrant
committed
Merge branch 'special-array' into enhancer-callback-2
2 parents a390f47 + 107db6d commit 7497f73

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

docs/usage/usage-with-typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export default store
136136

137137
#### Using `Tuple` without `getDefaultMiddleware`
138138

139-
If you want to skip the usage of `getDefaultMiddleware` altogether, you are requred to use `Tuple` for type-safe creation of your `middleware` array. This class extends the default JavaScript `Array` type, only with modified typings for `.concat(...)` and the additional `.prepend(...)` method.
139+
If you want to skip the usage of `getDefaultMiddleware` altogether, you are required to use `Tuple` for type-safe creation of your `middleware` array. This class extends the default JavaScript `Array` type, only with modified typings for `.concat(...)` and the additional `.prepend(...)` method.
140140

141141
For example:
142142

packages/toolkit/src/tests/Tuple.typetest.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { expectType } from './helpers'
1414
// @ts-expect-error
1515
expectType<Tuple<[string, string]>>(stringTuple)
1616

17-
const numberTuple = new Tuple(0)
17+
const numberTuple = new Tuple(0, 1)
1818
// @ts-expect-error
1919
expectType<Tuple<string[]>>(numberTuple)
2020
}
@@ -63,19 +63,19 @@ import { expectType } from './helpers'
6363
{
6464
const stringTuple = new Tuple('')
6565

66-
const numberTuple = new Tuple(0)
66+
const numberTuple = new Tuple(0, 1)
6767

68-
expectType<Tuple<[string, number]>>(stringTuple.concat(numberTuple))
68+
expectType<Tuple<[string, number, number]>>(stringTuple.concat(numberTuple))
6969

70-
expectType<Tuple<[number, string]>>(stringTuple.prepend(numberTuple))
70+
expectType<Tuple<[number, number, string]>>(stringTuple.prepend(numberTuple))
7171

72-
expectType<Tuple<[number, string]>>(numberTuple.concat(stringTuple))
72+
expectType<Tuple<[number, number, string]>>(numberTuple.concat(stringTuple))
7373

74-
expectType<Tuple<[string, number]>>(numberTuple.prepend(stringTuple))
74+
expectType<Tuple<[string, number, number]>>(numberTuple.prepend(stringTuple))
7575

7676
// @ts-expect-error
77-
expectType<Tuple<[string, number]>>(stringTuple.prepend(numberTuple))
77+
expectType<Tuple<[string, number, number]>>(stringTuple.prepend(numberTuple))
7878

7979
// @ts-expect-error
80-
expectType<Tuple<[number, string]>>(stringTuple.concat(numberTuple))
80+
expectType<Tuple<[number, number, string]>>(stringTuple.concat(numberTuple))
8181
}

packages/toolkit/src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ export function find<T>(
4040
return undefined
4141
}
4242

43-
export class Tuple<Items extends ReadonlyArray<unknown>> extends Array<
43+
export class Tuple<Items extends ReadonlyArray<unknown> = []> extends Array<
4444
Items[number]
4545
> {
46-
constructor(...items: Items) {
46+
constructor(length: number)
47+
constructor(...items: Items)
48+
constructor(...items: any[]) {
4749
super(...items)
4850
Object.setPrototypeOf(this, Tuple.prototype)
4951
}

0 commit comments

Comments
 (0)