diff --git a/src/constructors.ts b/src/constructors.ts index 66b57044..229e2027 100644 --- a/src/constructors.ts +++ b/src/constructors.ts @@ -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 any>(fn: T): Composable { +function composable( + fn: T, +): Composable any ? T : never> { return async (...args) => { try { // deno-lint-ignore no-explicit-any diff --git a/src/tests/constructors.test.ts b/src/tests/constructors.test.ts index 14da023e..6d20dd49 100644 --- a/src/tests/constructors.test.ts +++ b/src/tests/constructors.test.ts @@ -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 any>>> + }) + it('infers the types of async functions', async () => { const fn = composable(asyncAdd) const res = await fn(1, 2) @@ -110,7 +116,7 @@ describe('fromSuccess', () => { const a = composable(() => 1) const c = fromSuccess(a) - type _R = Expect Promise>> + type _R = Expect Promise<1>>> assertEquals(await c(), 1) }) @@ -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<