Skip to content

Commit

Permalink
fix(ii): 优化类型推导
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Sep 29, 2021
1 parent 9bd36e0 commit 98d388d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/utils/ii.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ii } from './ii'
describe('ii', () => {
test('表现正常', async () => {
expect(ii(() => 1)).toBe(1)
expect(await ii(() => Promise.resolve(1))).toBe(1)
const n: number = await ii(() => Promise.resolve(1))
expect(n).toBe(1)
})
})
4 changes: 1 addition & 3 deletions src/utils/ii.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { AnyFunction } from '../types'

/**
* 立即调用函数并返回其返回值。
*
Expand All @@ -12,6 +10,6 @@ import { AnyFunction } from '../types'
* ii(() => 1) // => 1
* ```
*/
export function ii<F extends AnyFunction>(fn: F): ReturnType<F> {
export function ii<R, F extends () => R = () => R>(fn: F): R {
return fn()
}

0 comments on commit 98d388d

Please sign in to comment.