-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add JSDoc Support #38
Comments
It seems interesting, would you mind opening a PR with your code? |
@Eomm Thanks. Unfortunately, I couldn't make it work. I'd be glad to create an example project if needed. |
This is the way forward!!
I'd love to see fastify play nicely with TS typings in JS too... |
Hey guys, you can do this: It should autocomplete the params and also can validate the types if you define a /** @typedef {import('@fastify/type-provider-typebox').TypeBoxTypeProvider} TypeBoxTypeProvider */
import createFastify from 'fastify'
import { TypeBoxValidatorCompiler } from '@fastify/type-provider-typebox'
import { Type } from '@sinclair/typebox'
const fastify = createFastify()
/** @type {ReturnType<typeof fastify.withTypeProvider<TypeBoxTypeProvider>>} */
const api = fastify
.setValidatorCompiler(TypeBoxValidatorCompiler)
.withTypeProvider()
api.get('/', {
schema: {
querystring: Type.Object({
x: Type.String(),
y: Type.String(),
z: Type.String()
})
}
}, (req) => {
const { x } = req.query
}) |
Wow! |
Prerequisites
馃殌 Feature Proposal
Unfortunately, Typescript doesn't support inline generics with JSDoc, yet. microsoft/TypeScript#27387
But AFAIK, there should be no difference between JSDoc and Typescript on this matter.
I tried to make it work without the need to override the type again and again but failed.
I'm not a Typescript expert, so I would appreciate it if someone could take a look.
Motivation
Use Typebox provider in JS + JSDoc projects (typescript only as a type checker without compiling the code)
Example
No response
The text was updated successfully, but these errors were encountered: