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

bug: types broken after setting a basepath #2832

Closed
thenbe opened this issue May 28, 2024 · 12 comments · Fixed by #2834
Closed

bug: types broken after setting a basepath #2832

thenbe opened this issue May 28, 2024 · 12 comments · Fixed by #2834
Labels

Comments

@thenbe
Copy link

thenbe commented May 28, 2024

What version of Hono are you using?

4.4.0

What runtime/platform is your app running on?

node

What steps can reproduce the bug?

Typescript playground repro: link

What is the expected behavior?

There should be a way to create a typed testClient when using a basepath.

What do you see instead?

testClient types are broken when using a basepath.

Additional information

No response

@thenbe thenbe added the bug label May 28, 2024
@EdamAme-x
Copy link
Contributor

I understood.
The type of Env is conflict.

Argument of type 'Hono<Env, BlankSchema, "/mybasepath">' is not assignable to parameter of type 'Hono<{}, { "/mybasepath/items": { $get: { input: {}; output: { id: number; }; outputFormat: "json"; status: 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | ... 47 more ... | -1; }; }; }, "/mybasepath">'.
  Types of property 'fetch' are incompatible.
    Type '(request: Request, Env?: {} | Bindings | undefined, executionCtx?: ExecutionContext | undefined) => Response | Promise<Response>' is not assignable to type '(request: Request, Env?: unknown, executionCtx?: ExecutionContext | undefined) => Response | Promise<Response>'.
      Types of parameters 'Env' and 'Env' are incompatible.
        Type 'unknown' is not assignable to type '{} | Bindings | undefined

Env has two types of {} and unknown.

@EdamAme-x
Copy link
Contributor

Env?: ExtractEnv<T>['Bindings'] | {},

@EdamAme-x
Copy link
Contributor

Explicitly unknown is not specified.

@EdamAme-x
Copy link
Contributor

EdamAme-x commented May 28, 2024

image

@EdamAme-x
Copy link
Contributor

EdamAme-x commented May 28, 2024

image

@EdamAme-x
Copy link
Contributor

ReturnType of ".get" is broken...?

@EdamAme-x
Copy link
Contributor

image

@EdamAme-x
Copy link
Contributor

EdamAme-x commented May 28, 2024

image

enviroment in not using basePath

@EdamAme-x
Copy link
Contributor

Either way, the returnType Env of .get will be unknown.

@EdamAme-x
Copy link
Contributor

image

@EdamAme-x
Copy link
Contributor

image
maybe IntersectNonAnyTypes<[E, E2]> is unknown

@EdamAme-x
Copy link
Contributor

@thenbe
image
This problem can be worked around by specifying the Env directly.
But this is only temporary.

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