Open Christian-Harnisch-DB opened 6 days ago
Hello,
I've never used the lib with a d.ts
type declaration file but:
declare
keyword causes the error you encounter (was able to reproduce with only one type declaration)ts-to-zod
could handle it (which should not be too hard to add), the file you mention contains class declarations which are not supported yet by the lib (see https://github.com/fabien0102/ts-to-zod/issues/268): we only support the interface part of classes, not the z.instanceof
equivalent.
Bug description
I'm trying to generate Zod schemas from a types.d.ts file. However, no output file is written and the error message "SyntaxError: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference" is logged. This seems to be related to the input file being a
d.ts
file, but my experience with TypeScript is rather limited so I don't know what the actual issue is.Input
This file from prometheus-query-js. The (Powershell) CLI command is
npx ts-to-zod .\node_modules\prometheus-query\dist\types.d.ts .\build\types.zod.ts
. Adding--skipValidation
to the CLI command just suppresses the line "√ Validating generated types".Expected output
A file with Zod schemas
Actual output
Versions
v5.6.2
v3.23.8
v3.14.1