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

Unknown IndexedAccessTypeNode.objectType type #116

Open
sebkasanzew opened this issue Feb 28, 2023 · 2 comments
Open

Unknown IndexedAccessTypeNode.objectType type #116

sebkasanzew opened this issue Feb 28, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@sebkasanzew
Copy link

sebkasanzew commented Feb 28, 2023

Bug description

I try to get rid of enums in my codebase. So in the schema world this means having z.union([z.literal('...')]) or z.literal('...') instead of z.nativeEnum(...).

But it seems like this common replace syntax for enums is not supported by ts-to-zod.

Input

export const MyCases = {
  Test: 'Case',
} as const

export type MyCase = (typeof MyCases)[keyof typeof MyCases]

Expected output

const myCaseSchema = z.literal('Case')

Actual output

Error: Unknown IndexedAccessTypeNode.objectType type

Versions

  • Typescript: v4.9.5
  • Zod: v3.20.6
@mittalbhanderi
Copy link

The exact same error is thrown when the input is an array:

export const Data = [ "a", "b"] as const;

@persovt2
Copy link


export const TranslationFilterFromEnum = {
    Ru: 'RU',
    En: 'EN',
    Zh: 'ZH'
};

export type TranslationFilterFromEnum = typeof TranslationFilterFromEnum[keyof typeof TranslationFilterFromEnum];

This example doesn't work either

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

4 participants