-
Notifications
You must be signed in to change notification settings - Fork 70
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
Generated type validation doesn't work for non-optional any property #140
Comments
Interesting! I guess we can relax the validator for this usecase. The validator is here to help discovering missing types, so I think it's fine to ignore this case, I can have a look on Monday if you want! 😊 Have a nice weekend |
Hello @fabien0102, Have you had a chance to look at this? |
As you probably guessed, I had no time whatsoever 🙈 Until now! 😁 This should be fixed, thanks again for the clear reporting and follow up |
* test: failing test case * test: additional test case * feat: new util function to extract import identifiers * feat: more import utils, in their own file * feat: add new helper generating instanceof * feat: adding non-relative import handling of classes * doc: adding documentation * test: adding extend test case * clean: remove moved tests after rebase * test: union case test * fix: remove unused const * feat: allow any module import (relative & non-relative) * test: add test to cover issue #140 * fix: same behavior as #140 with 3rd party imports * feat: make arg optional * fix: update tests after Jest update * fix: typo in tests * feat: enabling refs to extra files in post-generation validation * revert switch to generic fixOptional * fix: remove instanceof handling * clean: remove wrongly commited file * clean: remove unused isRelativeModuleImport * doc: rework * fix: missing makePosixPath after rebase * clean: removing commented out bits --------- Co-authored-by: tvillaren <[email protected]>
* test: failing test case * test: additional test case * feat: new util function to extract import identifiers * feat: more import utils, in their own file * feat: add new helper generating instanceof * feat: adding non-relative import handling of classes * doc: adding documentation * test: adding extend test case * clean: remove moved tests after rebase * test: union case test * fix: remove unused const * feat: allow any module import (relative & non-relative) * test: add test to cover issue #140 * fix: same behavior as #140 with 3rd party imports * feat: make arg optional * fix: update tests after Jest update * fix: typo in tests * feat: enabling refs to extra files in post-generation validation * revert switch to generic fixOptional * fix: remove instanceof handling * clean: remove wrongly commited file * clean: remove unused isRelativeModuleImport * doc: rework * fix: missing makePosixPath after rebase * test: adding failing tests * fix: typo * fix: complex array were not traversed * fix: missing TS helpers in type extractor * test: failing test case * test: additional test case * fix: same behavior as #140 with 3rd party imports * feat: add createImport function * feat: handle input / output mapping as source for generate * feat: add zod import handling from config file * doc: adding documentation for ZOD imports * refacto test * test: adding hybrid import * test: adding new test * fix: using relative to compare paths * fix: multiple fixes after rebase * fix: remove useless imports from output * update documentation * fix: build issues after rebase --------- Co-authored-by: tvillaren <[email protected]>
Bug description
When using the
any
keyword to accept any input for a property, like this:ts-to-zod
generates the right outputHowever, as mentioned in issue colinhacks/zod#1628, the type inference from
zod
makes thename
property optional, failing thets-to-zod
generated type validation (see 52cf4f7 for a failing test case).Indeed, when looking at the inferred type via
z.infer<typeof citizenSchema>
we get the following:which doesn't match the initial type, thus fail validation.
There is no full consensus on the fix on the
zod
Github.👉 An user proposed a workaround but that would mean using a custom function instead of
z.object()
.👉 We could ignore this specific generated type validation error, but it may come from various sources.
👉 We could live with it, but that would mean only supporting
any
for optional properties (and thus, warnts-to-zod
users about this upon generation).Happy to try to fix this but not sure toward which direction we could go 🤷
The text was updated successfully, but these errors were encountered: