-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Allow an explicitly specified infer type #782
Comments
I would propose |
Have a working implementation for this! Autocomplete for keys, optional keys, works for tuples, etc.! Will add to the next release (may still change the name) 😊 DeclaredTypes.mp4 |
Ended up going with: type Expected = { a: string; b?: number }
const t = declare<Expected>().type({
a: "string",
"b?": "number"
}) Will add declarations for |
this is really nice, thank you very much ! |
hello, is there any news regarding this? it seem that |
@afoures Yes, very sorry for the delay! This is in the upcoming 2.0 release. I will close this issue once it is merged and published. In the meantime I've been publishing a few preview dev builds, feel free to check out the ArkType Discord if interested. |
@afoures This is available in |
thanks for the heads up! 🙏🏻 |
Discussed in #781
Originally posted by afoures June 1, 2023
Hi,
Is there a way to type check schema implementation from an existing type?
Something like this:
Related issue from zod -> colinhacks/zod#372
Thanks to @afoures for submitting this! Would definitely be a valuable feature. Currently you can do something like this:
But TS's comparison is structural and covariant, i.e. you could add extra fields to your validator and it would still work as long as everything in the type itself is covered.
I tried adding an
in out
annotation toType
's inference parameter, but it broke a bunch of other things I'd have to look into, so I'm creating this issue and adding it to the backlog to create a dedicated API for this.If in the meantime you'd benefit from something like the above, feel free to use that, or you could write a custom function to do an
equals
comparison on the types as an extra validation step if needed.The text was updated successfully, but these errors were encountered: