Z
Zod3d ago
Josh

Josh - hey, why the heck is this invalid?ts ...

hey, why the heck is this invalid?
type ResponseSchema = (typeof API)[T]["responseSchema"];
const responseSchema: ResponseSchema = API[methodName].responseSchema;

const parseResult = responseSchema.safeParse(json);
if (parseResult.success) {
this.logger.debug(
"Response for '%s' successfully parsed.",
methodName,
parseResult.data,
);
const data: z.infer<ResponseSchema> = parseResult.data;
// ^^^^ error TS2322: Type '{ ... }' is not assignable to type 'output<ResponseSchema>'
return [true, data];
}
type ResponseSchema = (typeof API)[T]["responseSchema"];
const responseSchema: ResponseSchema = API[methodName].responseSchema;

const parseResult = responseSchema.safeParse(json);
if (parseResult.success) {
this.logger.debug(
"Response for '%s' successfully parsed.",
methodName,
parseResult.data,
);
const data: z.infer<ResponseSchema> = parseResult.data;
// ^^^^ error TS2322: Type '{ ... }' is not assignable to type 'output<ResponseSchema>'
return [true, data];
}
1 Reply
Josh
JoshOP3d ago
GitHub
Zod 4 regression: parsing with schema of indexed access type · Iss...
I’m using indexed access types to select between several Zod schemas of different output types depending on a key. Using TypeScript 5.9.2, this type checks successfully with Zod 3.25.76 but not wit...

Did you find this page helpful?