Skip to content
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

Open
rehatch-yoshimori-otsuka opened this issue Feb 14, 2024 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@rehatch-yoshimori-otsuka
Copy link

rehatch-yoshimori-otsuka commented Feb 14, 2024

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 nothing

Additional information

example code

app/routes/companies/[companyId]/[postId]/index.ts

import { zValidator } from '@hono/zod-validator'
import { createRoute } from 'honox/factory'
import { object, string } from 'zod'

const paramsSchema = object({
  companyId: string(),
  postId: string(),
})

// before route.get('companies/:companyId/:postId',async (c) => {
// try const GET = createRoute<{ in: { param: ParamSchema } }>(async (c) => {
const GET = createRoute(zValidator('param', paramsSchema), async (c) => {
  // 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
// type 
const GET: [H<Env, any, {
    in: {
        param: {
            companyId: string;
            postId: string;
        };
    };
    out: {
        param: {
            companyId: string;
            postId: string;
        };
    };
}, Promise<Response & TypedResponse<...>>>, H<...>]
@rehatch-yoshimori-otsuka rehatch-yoshimori-otsuka added the enhancement New feature or request label Feb 14, 2024
@rehatch-yoshimori-otsuka
Copy link
Author

rehatch-yoshimori-otsuka commented Feb 14, 2024

in my case, I can find the solution for above case.

now still path parameter(c.req.param('companyId')) has no suggestion

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

@yusukebe
Copy link
Member

Hi @rehatch-yoshimori-otsuka

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!

@rehatch-yoshimori-otsuka
Copy link
Author

rehatch-yoshimori-otsuka commented Feb 15, 2024

@yusukebe
Thank you for your reading!
I understand what you tell me.

Yeah, this is a known issue and not a bug.
We can close this issue,

OK! you can close this issue without fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants