Skip to content

Commit

Permalink
feat(types): Fn
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Feb 1, 2023
1 parent 429bc12 commit 6e140b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/types/__tests__/fn.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file Type Tests - Fn
* @module tutils/types/tests/unit-d/Fn
*/

import type ANY from '../any'
import type TestSubject from '../fn'

describe('unit-d:types/Fn', () => {
it('should be callable with Args', () => {
expectTypeOf<TestSubject>().parameters.toEqualTypeOf<ANY[]>()
expectTypeOf<TestSubject<[string]>>().parameters.toEqualTypeOf<[string]>()
})

it('should return Ret', () => {
expectTypeOf<TestSubject>().returns.toEqualTypeOf<ANY>()
expectTypeOf<TestSubject<ANY, string>>().returns.toBeString()
})
})
18 changes: 18 additions & 0 deletions src/types/fn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @file Type Definitions - Fn
* @module tutils/types/Fn
*/

import type ANY from './any'

/**
* A function.
*
* @template Args - Arguments type
* @template Ret - Return type
*/
type Fn<Args extends ANY[] = ANY[], Ret extends ANY = ANY> = (
...args: Args
) => Ret

export type { Fn as default }
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type {
default as ExactOptionalPropertyTypes
} from './exact-optional-property-types'
export type { default as FIXME } from './fixme'
export type { default as Fn } from './fn'
export type { default as IndexSignature } from './index-signature'
export type { default as IsTuple } from './is-tuple'
export type { default as Join } from './join'
Expand Down

0 comments on commit 6e140b4

Please sign in to comment.