Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit recognition failed #232

Open
hlg-facai opened this issue Apr 15, 2024 · 1 comment
Open

Omit recognition failed #232

hlg-facai opened this issue Apr 15, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@hlg-facai
Copy link

Bug description

Omit recognition failed

Input

interface BaseElement {
    type: string;
    left: 0;
    top: 0;
}
export interface ImageElement extends Omit<BaseElement, 'type'> {
    type: 'image';
}

Expected output

// Generated by ts-to-zod
import { z } from 'zod';

const baseElementSchema = z.object({
    type: z.string(),
    left: z.literal(0),
    top: z.literal(0),
});

export const imageElementSchema = baseElementSchema.omit({ type: true }).extend({
    type: z.literal('image'),
});

Actual output

// Generated by ts-to-zod
import { z } from 'zod';

const baseElementSchema = z.object({
    type: z.string(),
    left: z.literal(0),
    top: z.literal(0),
});

Versions

  • Typescript: v5.2.22
  • Zod: v3.8.3
@tvillaren tvillaren added the enhancement New feature or request label Apr 15, 2024
@tvillaren
Copy link
Collaborator

Hello,

As a potential workaround, this does work with a type:

type BaseElement = {
  type: string;
  left: 0;
  top: 0;
};

export type ImageElement = Omit<BaseElement, "type"> & {
  type: "image";
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants