Skip to content

Commit 7b7391d

Browse files
author
Ben Grynhaus
committed
bugfix: make asyncThrottle more type-safe
now infers the type of arguments of `func` correctly
1 parent db83b21 commit 7b7391d

File tree

1 file changed

+4
-4
lines changed
  • src/createAsyncStoragePersistor-experimental

1 file changed

+4
-4
lines changed

src/createAsyncStoragePersistor-experimental/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ export const createAsyncStoragePersistor = ({
5151
}
5252
}
5353

54-
function asyncThrottle<T>(
55-
func: (...args: ReadonlyArray<unknown>) => Promise<T>,
54+
function asyncThrottle<Args extends readonly unknown[], Result>(
55+
func: (...args: Args) => Promise<Result>,
5656
{ interval = 1000, limit = 1 }: { interval?: number; limit?: number } = {}
5757
) {
5858
if (typeof func !== 'function') throw new Error('argument is not function.')
5959
const running = { current: false }
6060
let lastTime = 0
6161
let timeout: number
62-
const queue: Array<any[]> = []
63-
return (...args: any) =>
62+
const queue: Array<Args> = []
63+
return (...args: Args) =>
6464
(async () => {
6565
if (running.current) {
6666
lastTime = Date.now()

0 commit comments

Comments
 (0)