We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
query
[email protected]
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:
elysia/src/types.ts
Line 205 in 968650b
The text was updated successfully, but these errors were encountered:
Yess, this is needed!
Sorry, something went wrong.
0ee7eef
Merge pull request #636 from mnpenner/main
043bb6b
Fix #635 - Use StaticDecode<> instead of Static<> to get type of inpu…
No branches or pull requests
What version of Elysia.JS is running?
[email protected]
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:
elysia/src/types.ts
Line 205 in 968650b
The text was updated successfully, but these errors were encountered: