-
Notifications
You must be signed in to change notification settings - Fork 32
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[suggestion] base-x routing path-parameter type is any #53
Comments
in my case, I can find the solution for above case. now still path parameter( import { zValidator } from '@hono/zod-validator'
import { createRoute } from 'honox/factory'
import { object, string } from 'zod'
const paramsSchema = object({
companyId: string(),
postId: string(),
})
// try const GET = createRoute<{ in: { param: ParamSchema } }>(async (c) => {
const GET = createRoute(zValidator('param', paramsSchema), async (c) => {
+ // works! suggestion for 'companyId'
+ const { companyId, postId } = c.req.valid('param')
// not working. no suggestion for 'companyId' because param<any>(key: string) is any Generics
- // const companyId = c.req.param('companyId')
- // const postId = c.req.param('postId')
return c.json({})
})
// biome-ignore lint/style/noDefaultExport: Router specification
export default GET |
Yeah, this is a known issue and not a bug. But, it's too difficult or impossible to support inferring path params without changing APIs. We can close this issue, but let it keep open for a while, we might have a good idea. Thanks! |
@yusukebe
OK! you can close this issue without fixing this! |
Note
You can ignore if you can not get this issue clearly.
I understand this honox project is alpha version.
What is the feature you are proposing?
I need type suggestion for path parameter(
c.req.param()
) in createRoute.What version of HonoX are you using?
0.1.0
What steps can reproduce the bug?
create a new project via pnpm create@hono and x-basic
add a directory structure with 2 dynamic path parameters (app/routes/companies/[companyId]/[postId]/index.ts)
What is the expected behavior?
When I type
c.req.param('
then the VSCode(TS Server) suggest 'companyId' and 'postId'What do you see instead?
When I type
c.req.param('
then the VSCode(TS Server) suggest nothingAdditional information
example code
app/routes/companies/[companyId]/[postId]/index.ts
The text was updated successfully, but these errors were encountered: