Closed mnpenner closed 2 months ago
elysia@1.0.18
Linux 4.4.0-19041-Microsoft x86_64 x86_64
Create a type transform like:
import {t} from "elysia" export const PageToken = () => t.Transform(t.String()) .Decode(decodeToken) .Encode(encodeToken)
Then type your route:
{ query: t.Object({ afterCursor: PageToken(), }) }
query.afterCursor should have the type of the return value of decodeToken
query.afterCursor
decodeToken
query.afterCursor is typed as string (the input type coming from the client)
string
I haven't looked at Elysia's source code yet, but I'm guessing Elysia us using Static to infer the type when StaticDecode should be used instead: https://github.com/sinclairzx81/typebox?tab=readme-ov-file#transform-types
Static
StaticDecode
There's another example of transforms on that page that's perhaps better than mine.
Edit: I think this line is the culprit:
https://github.com/elysiajs/elysia/blob/968650becd19850e4f33dca273d9e5838c937d70/src/types.ts#L205
Yess, this is needed!
What version of Elysia.JS is running?
elysia@1.0.18
What platform is your computer?
Linux 4.4.0-19041-Microsoft x86_64 x86_64
What steps can reproduce the bug?
Create a type transform like:
Then type your route:
What is the expected behavior?
query.afterCursor
should have the type of the return value ofdecodeToken
What do you see instead?
query.afterCursor
is typed asstring
(the input type coming from the client)Additional information
I haven't looked at Elysia's source code yet, but I'm guessing Elysia us using
Static
to infer the type whenStaticDecode
should be used instead: https://github.com/sinclairzx81/typebox?tab=readme-ov-file#transform-typesThere's another example of transforms on that page that's perhaps better than mine.
Edit: I think this line is the culprit:
https://github.com/elysiajs/elysia/blob/968650becd19850e4f33dca273d9e5838c937d70/src/types.ts#L205