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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for transform types #125

Open
2 tasks done
ehaynes99 opened this issue Feb 7, 2024 · 2 comments
Open
2 tasks done

Support for transform types #125

ehaynes99 opened this issue Feb 7, 2024 · 2 comments

Comments

@ehaynes99
Copy link

ehaynes99 commented Feb 7, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

馃殌 Feature Proposal

Now that TypeBox supports transform types, it would be great if this library supported them as well.

Example

I made a branch that should work here: main...ehaynes99:fastify-type-provider-typebox:transform-types

However, this lib currently allows TypeBox versions down to 0.26, and transform types were only added in 0.30. I could work around it for the actual conversion like here:

// Decode added in TypeBox 0.30
const decoded = ('Decode' in Value) ? Value.Decode(schema, converted) : converted

but there's not a way to fix the types, because StaticDecode would not exist in those older versions. In order to merge this, the compatible version range would have to be updated.

diff --git a/package.json b/package.json
index e6af223..783bda7 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
     }
   },
   "peerDependencies": {
-    "@sinclair/typebox": ">=0.26 <=0.32"
+    "@sinclair/typebox": ">=0.30 <=0.32"
   },
   "scripts": {
     "build:clean": "rimraf ./dist",
@mcollina
Copy link
Member

mcollina commented Feb 7, 2024

I'm not sure what eversion are you using?

"@sinclair/typebox": ">=0.26 <=0.32"
lists v0.32.

@ehaynes99
Copy link
Author

ehaynes99 commented Feb 8, 2024

The peer dependency allows a range. E.g. an application could have 0.29, and that would not compile because the StaticDecode type would not exist. The minimum would have to be increased, as applications with >=0.30 <=0.32 would work, but those with >=0.26 <0.30 would not. I went ahead and made a PR with that in it, but wanted to point it out.

export interface TypeBoxTypeProvider extends FastifyTypeProvider {
output: this['input'] extends TSchema ? StaticDecode<this['input']> : unknown
}

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 a pull request may close this issue.

2 participants