fastify-type-provider-typebox
fastify-type-provider-typebox copied to clipboard
Support for transform types
Prerequisites
- [X] I have written a descriptive issue title
- [X] 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: https://github.com/fastify/fastify-type-provider-typebox/compare/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",
I'm not sure what eversion are you using? https://github.com/fastify/fastify-type-provider-typebox/blob/c92a5fb4fa01866f49c58989a2f01391e42337d3/package.json#L21 lists v0.32.
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.
https://github.com/fastify/fastify-type-provider-typebox/blob/b5647cba4452c8277e26928a21dacf38c5f322b5/index.mts#L61-L63