decs / typeschema

🛵 Universal adapter for TypeScript schema validation.
https://typeschema.com
MIT License
402 stars 13 forks source link

Fix Schema is not inferred when typebox is not installed for @typeschema/main #70

Closed nlfmt closed 1 month ago

nlfmt commented 1 month ago

When using @typeschema/main, a validation library other that typebox and its adapter, typeschema will try to infer all Schemas as typebox Schemas, due to the IsTypeboxSchema type always returning true which is caused by a missing import of @sinclair/typebox. A workaround is to install @sinclair/typebox, which is not ideal for libraries. (See #63)

My solution is to not use the Kind symbol to detect a Typebox Schema at the type level, but to use the properties static and params that are guaranteed to be in the Typebox TSchema instead.

I've run the tests and tried out the modified code with zod, suretype and typebox in various configurations, there seem to not be any issues.

I'm not quite sure how this works with Typebox' custom type system, but i couldn't find more documentation about their custom types for now

changeset-bot[bot] commented 1 month ago

⚠️ No Changeset found

Latest commit: 6dda722dee984f6adf35aca1599f1abda3c00551

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR