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

ctx.req.query() should return Record<string, string | undefined> #3426

Open
cesaryuan opened this issue Sep 20, 2024 · 2 comments
Open

ctx.req.query() should return Record<string, string | undefined> #3426

cesaryuan opened this issue Sep 20, 2024 · 2 comments
Labels
enhancement New feature or request.

Comments

@cesaryuan
Copy link

What version of Hono are you using?

4.6.2

What runtime/platform is your app running on?

Not matter

What steps can reproduce the bug?

I think the return type of c.req.query() should be Record<string, string | undefined> instead of Record<string, string>

The latter will cause the following code to compile without errors, but to actually run with errors:

const { name } = c.req.query();
return c.text(name.toUpperCase());

What is the expected behavior?

The return type of c.req.query() should be Record<string, string | undefined>

What do you see instead?

Record<string, string>

Additional information

No response

@yusukebe
Copy link
Member

Hi @cesaryuan

This is like a bug, but it is a known issue ( sorry for not writing it explicitly). I also think this should be Record<string, string | undefined>. But the change will be breaking change. So, it will be introduced in the next major or minor versions with the announcement. I've left this issue as an enhancement and will consider it. Thank you!

@yusukebe yusukebe added enhancement New feature or request. and removed triage labels Sep 20, 2024
@nakasyou
Copy link
Contributor

Or, you can make noUncheckedIndexedAccess true in tsconfig.json.
By enable this, to access indexable object such as Record, Array have to be checked.

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

3 participants