Skip to content

Commit

Permalink
fix: type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Aug 1, 2020
1 parent f41e9e6 commit dab6415
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import fs from 'fs'
import { depend } from '../src'

test('injest option args', () => {
const handler = depend({ print: (text?: string) => alert(text) }, ({ print }, a?: string) => {
return print(a)
})

expect(handler.inject({ print: text => text })('test')).toBe('test')
expect(handler.inject({ print: text => text })()).toBeUndefined()
})

test('inject add', () => {
const add = (a: number, b: number) => a + b
const basicFn = depend({ add }, ({ add }, a: number, b: number, c: number) => add(a, b) * c)
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type Deps<T extends Record<string, any>> = {
: T[P]
}

export const depend = <T extends Record<string, any>, U extends [] | [any, ...any[]], V>(
export const depend = <T extends Record<string, any>, U extends any[], V>(
dependencies: T,
cb: (deps: Deps<T>, ...args: U) => V
) => {
Expand Down

0 comments on commit dab6415

Please sign in to comment.