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

4.4.7 broke array types in Context #3131

Closed
dustinsmith1024 opened this issue Jul 11, 2024 · 7 comments · Fixed by #3134
Closed

4.4.7 broke array types in Context #3131

dustinsmith1024 opened this issue Jul 11, 2024 · 7 comments · Fixed by #3134
Labels

Comments

@dustinsmith1024
Copy link

dustinsmith1024 commented Jul 11, 2024

What version of Hono are you using?

4.4.7+

What runtime/platform is your app running on?

Cloudflare Workers

What steps can reproduce the bug?

I am attempting to upgrade to the latest 4.4 versions and I get a types issue with Array based elements in the HonoContext.

Sample context:

export interface DC {
  name: string;
  url: string;
}

declare module 'hono' {
  interface ContextVariableMap {
    jwt: JWTInterface;
    dcs: DC[];
    allowAllOrigins: boolean;
    allowedOrigins: string[];
    appToken: string;
    appEnv: string;
  }
}

What is the expected behavior?

No type errors should happen. This doesn't happen on 4.4.6, so maybe related to #2987?

What do you see instead?

➜ pnpm run -F gateway-router tsc

> [email protected] tsc router
> tsc --noEmit                                 ~~

src/file.ts:327:16 - error TS7006: Parameter 'dc' implicitly has an 'any' type.

327       .filter((dc) => userDcs.includes(dc.name))
                   ~~

src/file.ts:328:13 - error TS7006: Parameter 'dc' implicitly has an 'any' type.

328       .map((dc) => {
                ~~

src/file.ts:50:40 - error TS7006: Parameter 'dc' implicitly has an 'any' type.

50     if (!body.dc || c.get('dcs').find((dc) => dc.name === body.dc) === undefined) {
                                          ~~

src/file2.ts:180:55 - error TS7006: Parameter 'allowed' implicitly has an 'any' type.

180         const allowed = c.get('allowedOrigins').find((allowed) => origin === allowed);
                                                          ~~~~~~~

Additional information

No response

@yusukebe
Copy link
Member

Hi @dustinsmith1024

Is this way of reproducing it correctly?

Area.mp4

If so, it does not throw errors. Can you provide a minimal project to reproduce it?

@dustinsmith1024
Copy link
Author

@yusukebe
Copy link
Member

@dustinsmith1024 Thanks. Will be fixed soon.

@dustinsmith1024
Copy link
Author

Awesome thanks - Should I be doing something different with Context to prevent it?

@yusukebe yusukebe added bug and removed triage labels Jul 13, 2024
@yusukebe
Copy link
Member

@dustinsmith1024

Should I be doing something different with Context to prevent it?

It's a bug, so you don't have to add anything. Just wait for a new version!

@yusukebe
Copy link
Member

Hi @dustinsmith1024

This may be fixed in the latest version v4.5.0. Can you try it?

@yusukebe
Copy link
Member

We can close this issue now. If you still have a problem, feel free to reopen.

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

Successfully merging a pull request may close this issue.

2 participants