avoidwork / filesize.js

JavaScript library to generate a human readable String describing the file size
https://filesizejs.com
BSD 3-Clause "New" or "Revised" License
1.61k stars 97 forks source link

[TypeScript] Return type reported to be incorrect when changing output type from the default #126

Closed alpha-tango-kilo closed 2 years ago

alpha-tango-kilo commented 3 years ago

Using TypeScript, I'm told that the following will return a string, which isn't correct:

fileSize(123123, { output: "object" });

What I expect to be able to do:

let { value, symbol, exponent } = fileSize(123123, { output: "object" });

Current workaround:

let { value, symbol, exponent } = fileSize(123123], { output: "object" }) as unknown as { value: number, symbol: string, exponent: number };

For clarity, it is actually an object that gets returned, just the type declarations are telling me I'm going to get a string

alpha-tango-kilo commented 3 years ago

Upon further usage, it seems the same seems to apply for all the different output options - they all say they're going to return string

avoidwork commented 3 years ago

File was lifted from https://github.com/DefinitelyTyped/DefinitelyTyped; I didn't write it. Feel free to open a PR with fix or updated from that repo.

bhavya32 commented 3 years ago

@avoidwork do you know even whatsapp web uses your code?

avoidwork commented 3 years ago

@bhavya32 cool; i didn't.