diff --git a/lib/util/result.ts b/lib/util/result.ts index 86f48acdf2620b..a4fff1f471f29a 100644 --- a/lib/util/result.ts +++ b/lib/util/result.ts @@ -1,5 +1,10 @@ -import type { SafeParseReturnType, ZodType, ZodTypeDef } from 'zod'; -import { ZodError, z } from 'zod'; +import type { + SafeParseReturnType, + input as ZodInput, + output as ZodOutput, + ZodType, +} from 'zod'; +import { NEVER, ZodError, ZodIssueCode } from 'zod'; import { logger } from '../logger'; type Val = NonNullable; @@ -532,30 +537,26 @@ export class Result { * Given a `schema` and `input`, returns a `Result` with `val` being the parsed value. * Additionally, `null` and `undefined` values are converted into Zod error. */ - static parse< - T, - Schema extends ZodType, - Input = unknown, - >( + static parse>( input: unknown, schema: Schema, - ): Result>, ZodError> { + ): Result>, ZodError>> { const parseResult = schema - .transform((result, ctx): NonNullable => { + .transform((result, ctx): NonNullable> => { if (result === undefined) { ctx.addIssue({ - code: z.ZodIssueCode.custom, + code: ZodIssueCode.custom, message: `Result can't accept nullish values, but input was parsed by Zod schema to undefined`, }); - return z.NEVER; + return NEVER; } if (result === null) { ctx.addIssue({ - code: z.ZodIssueCode.custom, + code: ZodIssueCode.custom, message: `Result can't accept nullish values, but input was parsed by Zod schema to null`, }); - return z.NEVER; + return NEVER; } return result; @@ -569,9 +570,9 @@ export class Result { * Given a `schema`, returns a `Result` with `val` being the parsed value. * Additionally, `null` and `undefined` values are converted into Zod error. */ - parse, Input = unknown>( + parse>( schema: Schema, - ): Result>, E | ZodError> { + ): Result>, E | ZodError>> { if (this.res.ok) { return Result.parse(this.res.val, schema); } @@ -862,9 +863,12 @@ export class AsyncResult * Given a `schema`, returns a `Result` with `val` being the parsed value. * Additionally, `null` and `undefined` values are converted into Zod error. */ - parse, Input = unknown>( + parse>( schema: Schema, - ): AsyncResult>, E | ZodError> { + ): AsyncResult< + NonNullable>, + E | ZodError> + > { return new AsyncResult( this.asyncResult .then((oldResult) => oldResult.parse(schema))