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

Wrong typing for readRawBody #223

Closed
P4sca1 opened this issue Nov 2, 2022 · 1 comment · Fixed by #207
Closed

Wrong typing for readRawBody #223

P4sca1 opened this issue Nov 2, 2022 · 1 comment · Fixed by #207
Labels
bug Something isn't working

Comments

@P4sca1
Copy link

P4sca1 commented Nov 2, 2022

readRawBody is meant to return a Buffer when encoding is set to false, but it always returns Promise<string | Buffer | undefined>. The reason is that Encoding extends false always returns false. The function likely needs a generic type parameter. Also, looking at the source code, the function seems to always return a Promise, and never returns a Buffer when encoding is set.

export function readRawBody (event: H3Event, encoding: Encoding = 'utf-8'): Encoding extends false ? Buffer : Promise<string | Buffer | undefined> {

The following type declaration should be correct

declare function readRawBody<E extends Encoding | false = 'utf-8'>(event: H3Event, encoding?: E): E extends false ? Promise<Buffer> : Promise<string | undefined>;
@pi0
Copy link
Member

pi0 commented Jun 20, 2023

/cc @danielroe

@pi0 pi0 closed this as completed in #207 Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants