-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
In the following code, bso evaluates to string, but it presumably should evaluate to the branded type just as the other types do.
I realize _input and _output are deprecated, but they are still there, and at least tRPC is still relying on them (though I have suggested migrating).
import { z } from 'zod';
const BrandedSchema = z.string().brand<'brand'>();
const WrappedSchema = z.object({ key: BrandedSchema });
type bso = typeof BrandedSchema._output;
type wso = (typeof WrappedSchema._output)['key'];
type bso2 = z.output<typeof BrandedSchema>;
type wso2 = z.output<typeof WrappedSchema>['key'];
// Type equality checker from https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650.
type Equals<X, Y> =
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
const _1: Equals<string, bso> = true;
const _2: Equals<string, wso> = false;
const _3: Equals<string, bso2> = false;
const _4: Equals<string, wso2> = false;Tested with TypeScript 5.9 and Zod v4.0.15.
Metadata
Metadata
Assignees
Labels
No labels