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

Adding JSDoc tag useStrict to output strict() modifier #131

Merged
merged 3 commits into from May 17, 2023

Conversation

tvillaren
Copy link
Collaborator

Why

This solves #78 using a new @useStrict JSDoc tag key.

/** @useStrict */
export interface A {
    a: string
}

will generate the following:

export const aSchema = z.object({
    a: z.string()
}).strict();

and

export interface A {
    /** @useStrict */
    a: {
        b: number
    }
}

will generate

export const aSchema = z.object({
    a: z.object({
        b: z.number()
    }).strict()
});

@tvillaren
Copy link
Collaborator Author

tvillaren commented May 16, 2023

Might be missing some safeguards to prevent use of strict on other types.
Happy to dig any alternative implementation if needed (e.g. a global option?)

@codecov-commenter
Copy link

codecov-commenter commented May 16, 2023

Codecov Report

Merging #131 (a7b4d72) into main (0db6307) will increase coverage by 0.03%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main     #131      +/-   ##
==========================================
+ Coverage   95.98%   96.01%   +0.03%     
==========================================
  Files          13       13              
  Lines         648      653       +5     
  Branches      261      263       +2     
==========================================
+ Hits          622      627       +5     
  Misses         26       26              
Impacted Files Coverage Δ
src/core/jsDocTags.ts 98.97% <100.00%> (+0.05%) ⬆️

README.md Outdated Show resolved Hide resolved
@fabien0102
Copy link
Owner

Nice PR! Regarding the safeguard, I think this is fine for now, as example we have @pattern that could have the same problem, and so far… this is not a problem!

Copy link
Owner

@fabien0102 fabien0102 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's ship! 🚀

@fabien0102 fabien0102 merged commit f73a676 into fabien0102:main May 17, 2023
3 checks passed
@tvillaren
Copy link
Collaborator Author

For some reason, it doesn't work on the full generation, added a test case here
I can work on that, but not before next week unfortunately.

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

Successfully merging this pull request may close these issues.

None yet

3 participants