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

Incorrect types for Bun.gunzipSync() #14472

Closed
touhidurrr opened this issue Oct 10, 2024 · 7 comments
Closed

Incorrect types for Bun.gunzipSync() #14472

touhidurrr opened this issue Oct 10, 2024 · 7 comments
Labels
bug Something isn't working types An issue with TypeScript types

Comments

@touhidurrr
Copy link

touhidurrr commented Oct 10, 2024

What version of Bun is running?

1.1.31-canary.9+ff476313a

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

const base64 = 'Some Gzip data encoded to Base64';
const array = Bun.gunzipSync(Buffer.from(data, 'base64'));

What is the expected behavior?

It works fine.

What do you see instead?

I see type errors.
Image

Additional information

Even though there was no type error previously, in the latest version there is even though Bun.gunzipSync() accepts Buffer properly. Without this you have to manually convert from Buffer to ArrayBuffer for no reason or use //@ts-ignore

@touhidurrr touhidurrr added bug Something isn't working typescript Something for TypeScript labels Oct 10, 2024
@RiskyMH RiskyMH added types An issue with TypeScript types and removed typescript Something for TypeScript labels Oct 12, 2024
@nektro
Copy link
Member

nektro commented Oct 15, 2024

works as expected with no errors

Image

Image

@nektro nektro closed this as completed Oct 15, 2024
@touhidurrr
Copy link
Author

touhidurrr commented Oct 15, 2024

works as expected with no errors

I am not sure why are you not seeing any errors. Because from your screenshot itself, it is saying that gunzipSync(data: string | Unit8Array | ArrayBuffer, ..., so the type of data is string | Unit8Array | ArrayBuffer. But we are passing Buffer here. And that is the error that I faced in my usage. (Argument of type Buffer cannot be assigned to type string | Unit8Array | ArrayBuffer) But you have the same types here but no errors?

Are you sure that you are on the latest version of typescript and @types/bun?

@touhidurrr
Copy link
Author

Ok, I found something interesting. With only @types/bun installed on the project, I am getting no error. But with both @types/bun and @types/node installed, this error appears. Since I was using Bun as a runtime in my project, I thought I did not need node types.

@nektro, I think this issue should be reopened and investigated.

@nektro
Copy link
Member

nektro commented Oct 15, 2024

Buffer extends from Unit8Array

will try reproducing with both packages when im at my computer next

@touhidurrr
Copy link
Author

@nektro, reminder ping

@nektro
Copy link
Member

nektro commented Dec 14, 2024

Ok, I found something interesting. With only @types/bun installed on the project, I am getting no error.

this is why i felt the issue should be closed

But with both @types/bun and @types/node installed, this error appears. Since I was using Bun as a runtime in my project, I thought I did not need node types.

this is correct. @types/bun itself depends on @types/node to fill in the definitions it does not define and so you should only need to directly devDepend on @types/bun. this is reflected in the default package.json created by bun init.

I am not sure why are you not seeing any errors. Because from your screenshot itself, it is saying that gunzipSync(data: string | Unit8Array | ArrayBuffer, ..., so the type of data is string | Unit8Array | ArrayBuffer. But we are passing Buffer here.

this is because as i said above, Buffer inherits from Unit8Array so that is the type it is being received as and passes the type-check.

And that is the error that I faced in my usage. (Argument of type Buffer cannot be assigned to type string | Unit8Array | ArrayBuffer) But you have the same types here but no errors? Are you sure that you are on the latest version of typescript and @types/bun?

there may have been a definition conflict of the Buffer global related to something along the lines of #8761 but it appears to have been fixed in this particular case given that u said above it now works with only @types/bun installed. i also recreated the example above in a new project with bun init and then did bun add @types/node and can confirm i still did not see the error in the latest versions of bun and the types packages.

if there's anything i've missed, am happy to look further :)

@touhidurrr
Copy link
Author

touhidurrr commented Dec 15, 2024

i also recreated the example above in a new project with bun init and then did bun add @types/node and can confirm i still did not see the error in the latest versions of bun and the types packages.

You have to do bun init then bun add @types/bun, and you must not install @types/node separately for this to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working types An issue with TypeScript types
Projects
None yet
Development

No branches or pull requests

3 participants