zod icon indicating copy to clipboard operation
zod copied to clipboard

JSDoc hints are lost after using `.extend`

Open todor-a opened this issue 10 months ago • 2 comments

Once you use .extend, any JSDoc hints are lost.

import { z } from 'zod';

const v1 = z.object({
    /** this works */
    userId: z.string(),
});

const v2 = z.object({
    /** this doesn't */
    itemId: z.string(),
}).extend(v1.shape);

const instance1: z.infer<typeof v1> = {
    userId: '2' // has hint on hover
}

const instance2: z.infer<typeof v2> = {
    itemId: '1',
    userId: '2'
}

Playground - https://tsplay.dev/w2oKzN

todor-a avatar Apr 24 '24 06:04 todor-a

In my experiments, this isn't a solvable problem, but perhaps others can succeed where I've failed.

colinhacks avatar Apr 26 '24 20:04 colinhacks

This works in 3.22.4

samchungy avatar May 03 '24 05:05 samchungy

Merged and landed in v3.23.7

colinhacks avatar May 07 '24 20:05 colinhacks