Skip to content

Commit 9b975a0

Browse files
committed
fix: update the type definition
1 parent f238297 commit 9b975a0

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/__tests__/main.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {useDebounce} from 'use-debounce'
77

88
test('get async data', async function () {
99
function getAsyncData() {
10-
return new Promise((resolve) => {
10+
return new Promise<number>((resolve) => {
1111
setTimeout(() => {
1212
resolve(1)
1313
}, 100)

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {DependencyList, useEffect, useState} from 'react'
22

3-
export function useAsyncMemo<T>(factory: () => Promise<T> | undefined | null, deps: DependencyList, initial: T = undefined): T {
4-
const [val, setVal] = useState<T>(initial)
3+
export function useAsyncMemo<T>(factory: () => Promise<T> | undefined | null, deps: DependencyList): T | undefined
4+
export function useAsyncMemo<T>(factory: () => Promise<T> | undefined | null, deps: DependencyList, initial: T): T
5+
export function useAsyncMemo<T>(factory: () => Promise<T> | undefined | null, deps: DependencyList, initial?: T) {
6+
const [val, setVal] = useState<T | undefined>(initial)
57
useEffect(() => {
68
let cancel = false
79
const promise = factory()

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"sourceMap": false,
44
"declaration": true,
5-
"noImplicitAny": true,
5+
"strict": true,
66
"target": "es5",
77
"module": "commonjs",
88
"jsx": "react",

0 commit comments

Comments
 (0)