Skip to content

strictObject changes behaviour in v4 #4823

@AntonioVentilii

Description

@AntonioVentilii

Just wondering if this is expected or not:

v3

No issue here

import * as z from 'zod';

const FooSchema = z.strictObject({});

const FooSchemaExtended = FooSchema.extend({
	value: z.string()
});

type Foo = z.infer<typeof FooSchema>;

type FooExtended = z.infer<typeof FooSchemaExtended>;

type PostMessage<T extends Foo> = T;

export type bar = PostMessage<FooExtended>;

v4

Issue on the last line

import * as z from 'zod/v4';

const FooSchema = z.strictObject({});

const FooSchemaExtended = FooSchema.extend({
	value: z.string()
});

type Foo = z.infer<typeof FooSchema>;

type FooExtended = z.infer<typeof FooSchemaExtended>;

type PostMessage<T extends Foo> = T;

export type bar = PostMessage<FooExtended>;

the last line raises an error (that was not raised in v3):

TS2344: Type { value: string; } does not satisfy the constraint Record<string, never>
Property value is incompatible with index signature.
Type string is not assignable to type never

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions