Skip to content

Commit bfada3e

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

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
@@ -49,16 +49,16 @@ export const createAsyncStoragePersistor = ({
4949
}
5050
}
5151

52-
function asyncThrottle<T>(
53-
func: (...args: ReadonlyArray<unknown>) => Promise<T>,
52+
function asyncThrottle<Args extends readonly unknown[], Result>(
53+
func: (...args: Args) => Promise<Result>,
5454
{ interval = 1000, limit = 1 }: { interval?: number; limit?: number } = {}
5555
) {
5656
if (typeof func !== 'function') throw new Error('argument is not function.')
5757
const running = { current: false }
5858
let lastTime = 0
5959
let timeout: number
60-
const queue: Array<any[]> = []
61-
return (...args: any) =>
60+
const queue: Array<Args> = []
61+
return (...args: Args) =>
6262
(async () => {
6363
if (running.current) {
6464
lastTime = Date.now()

0 commit comments

Comments
 (0)