From cae4be9dc3448c9bbcce2bb8b785653996f226a4 Mon Sep 17 00:00:00 2001 From: Diogo Biazus Date: Mon, 3 Jun 2024 11:34:48 -0400 Subject: [PATCH] Remove any types from applySchema --- src/constructors.ts | 28 ++++++++++++++++------------ src/tests/constructors.test.ts | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/constructors.ts b/src/constructors.ts index b6946983..de36ec01 100644 --- a/src/constructors.ts +++ b/src/constructors.ts @@ -134,15 +134,15 @@ function withSchema( function applySchema( inputSchema?: ParserSchema, environmentSchema?: ParserSchema, -): ( - fn: Composable<(input?: Input, environment?: Environment) => R>, -) => ParsedInput extends Input - ? ParsedEnvironment extends Environment - ? ComposableWithSchema - : Internal.FailToCompose - : Internal.FailToCompose { - return ((fn: any) => { - return (input?: unknown, environment?: unknown) => { +) { + return ( + fn: T, + ): ParsedInput extends Input + ? ParsedEnvironment extends Environment + ? ComposableWithSchema> + : Internal.FailToCompose + : Internal.FailToCompose => { + return ((input?: unknown, environment?: unknown) => { const envResult = (environmentSchema ?? alwaysUnknownSchema).safeParse( environment, ) @@ -162,9 +162,13 @@ function applySchema( ) return Promise.resolve(failure([...inputErrors, ...envErrors])) } - return fn(result.data as any, envResult.data as any) - } - }) as any + return fn(result.data as Input, envResult.data as Environment) + }) as ParsedInput extends Input + ? ParsedEnvironment extends Environment + ? ComposableWithSchema> + : Internal.FailToCompose + : Internal.FailToCompose + } } const alwaysUnknownSchema: ParserSchema = { diff --git a/src/tests/constructors.test.ts b/src/tests/constructors.test.ts index 8889eff4..cac70598 100644 --- a/src/tests/constructors.test.ts +++ b/src/tests/constructors.test.ts @@ -373,7 +373,7 @@ describe('applySchema', () => { ), ) type _R = Expect< - Equal> + Equal> > assertEquals(