JSDoc are ignored
See original GitHub issueBug description
JSDoc are ignored and not processed in schema output. I couldn’t investigate why this happens but it appears that parsed jsDoc array is always empty at this line. The parser doesn’t recognize other JSDoc (@type) at this point.
The library runs programmatically:
generate({
sourceText: data,
keepComments: true,
});
Same for CLI, with and without keepComments option.
Input
The same example as in documentation:
export interface HeroContact {
/**
* The email of the hero.
*
* @format email
*/
email: string;
/**
* The name of the hero.
*
* @minLength 2
* @maxLength 50
*/
name: string;
/**
* The phone number of the hero.
*
* @pattern ^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$
*/
phoneNumber: string;
/**
* Does the hero has super power?
*
* @default true
*/
hasSuperPower?: boolean;
/**
* The age of the hero
*
* @minimum 0
* @maximum 500
*/
age: number;
}
Expected output
Should be same as in docs:
export const heroContactSchema = z.object({
/**
* The email of the hero.
*
* @format email
*/
email: z.string().email(),
/**
* The name of the hero.
*
* @minLength 2
* @maxLength 50
*/
name: z.string().min(2).max(50),
/**
* The phone number of the hero.
*
* @pattern ^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$
*/
phoneNumber: z.string().regex(/^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$/),
/**
* Does the hero has super power?
*
* @default true
*/
hasSuperPower: z.boolean().default(true),
/**
* The age of the hero
*
* @minimum 0
* @maximum 500
*/
age: z.number().min(0).max(500),
});
Actual output
JSDocs are ignored in schema output:
export const heroContactSchema = z.object({
/**
* The email of the hero.
*
* @format email
*/
email: z.string(),
/**
* The name of the hero.
*
* @minLength 2
* @maxLength 50
*/
name: z.string(),
/**
* The phone number of the hero.
*
* @pattern ^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$
*/
phoneNumber: z.string(),
/**
* Does the hero has super power?
*
* @default true
*/
hasSuperPower: z.boolean(),
/**
* The age of the hero
*
* @minimum 0
* @maximum 500
*/
age: z.number()
});
Intermediate type output contains no changes, only indentation:
export interface HeroContact {
/**
* The email of the hero.
*
* @format email
*/
email: string;
/**
* The name of the hero.
*
* @minLength 2
* @maxLength 50
*/
name: string;
/**
* The phone number of the hero.
*
* @pattern ^([+]?d{1,2}[-s]?|)d{3}[-s]?d{3}[-s]?d{4}$
*/
phoneNumber: string;
/**
* Does the hero has super power?
*
* @default true
*/
hasSuperPower: boolean;
/**
* The age of the hero
*
* @minimum 0
* @maximum 500
*/
age: number;
}
Versions
- node v14.17.3
- ts-to-zod: v1.5.2
- Typescript: v4.2.3 (ts-to-zod own dependency)
- Zod: v3.11.2 (ts-to-zod own dependency)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Use JSDoc: @ignore
The @ignore tag indicates that a symbol in your code should never appear in the documentation. This tag takes precedence over all others....
Read more >JSDoc - How to document a parameter that is being ignored ...
As you can see, I am ignoring the first argument of the method using the underscore character. How can I document it in...
Read more >JSDoc @type annotation ignored in chained variable ... - GitHub
The official JSDoc documentation says nothing about mixing types within one var statement, but I guess that if the TS notation works, the ......
Read more >Javascript class not resolved, some JSDoc elements are ignored
4 some JSDoc elements to help InjelliJ resolve namespace and classes seems to be ignored. I get a lot of warnings and cannot...
Read more >@ignore | TypeDoc
@ignore. Tag Kind: Modifier; TSDoc Reference: TypeDoc specific. Reflections marked with the @hidden tag will ... It is equivalent to the @ignore JSDoc...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I ended up with the fix on my side:
a) provide level 1 dummy
tsutilsdep that prevents tsutils@3.21.0 from being hoisted from nested depsb) force typescript@4.2.3 for ts-to-zod because tsutils@3.21.0 somehow installed typescript@4.4.3 at ts-to-zod/node_modules/tsutils/node_modules/typescript , likely because of its loose peer dependency on typescript, although the reasoning for this never came up, probably a quirk of Yarn
I’m not sure whether this can be fixed on package level. Probably by informing users of possible implications if they install it locally together with other TS libs. I’m aware of hoisting problem, but this is the first time it messed up things for me in a very obscure way.
@bisubus Thanks for this amazing debugging!
Indeed, when I run your repro repo with npm instead of yarn, this is working as expected:
I’m also not sure how to fix this at the package level 😕 I will try to see what I can do to at least warn the user.
Thanks again for reporting & debugging this! 🎉