fastify / fastify/fastify-type-provider-typebox

Support for transform types

Open
#125 4 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
205
Forks
29
Avg merge
2m
Merged PRs (30d)
1

Description

### 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](https://github.com/sinclairzx81/typebox/blob/master/changelog/0.30.0.md), 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](https://github.com/ehaynes99/fastify-type-provider-typebox/blob/4a303c3387898aa83418dbb001e337a3f40bc813/index.mts#L32):

```typescript
// 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
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",
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.