Skip to content

Commit

Permalink
Merge pull request #147 from seasonedcc/no-implicit-any
Browse files Browse the repository at this point in the history
No implicit any
  • Loading branch information
diogob authored Jun 7, 2024
2 parents f88d8b8 + 17ffdb6 commit c540af3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ function toError(maybeError: unknown): Error {
* That function is gonna catch any errors and always return a Result.
* @param fn a function to be used as a Composable
*/
function composable<T extends (...args: any[]) => any>(fn: T): Composable<T> {
function composable<T extends Function>(
fn: T,
): Composable<T extends (...args: any[]) => any ? T : never> {
return async (...args) => {
try {
// deno-lint-ignore no-explicit-any
Expand Down
10 changes: 8 additions & 2 deletions src/tests/constructors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ describe('composable', () => {
assertEquals(res, success(3))
})

it('will enforce noImplicitAny', () => {
// @ts-expect-error: implicit any
const fn = composable((a) => a)
type _FN = Expect<Equal<typeof fn, Composable<(a: any) => any>>>
})

it('infers the types of async functions', async () => {
const fn = composable(asyncAdd)
const res = await fn(1, 2)
Expand Down Expand Up @@ -110,7 +116,7 @@ describe('fromSuccess', () => {
const a = composable(() => 1)

const c = fromSuccess(a)
type _R = Expect<Equal<typeof c, () => Promise<number>>>
type _R = Expect<Equal<typeof c, () => Promise<1>>>

assertEquals(await c(), 1)
})
Expand Down Expand Up @@ -145,7 +151,7 @@ describe('withSchema', () => {
assertEquals(await handler(), success('no input!'))
})

it('ignores the input and pass undefined', async () => {
it('defaults non-declared input to unknown', async () => {
const handler = withSchema()((args) => args)
type _R = Expect<
Equal<
Expand Down

0 comments on commit c540af3

Please sign in to comment.