Current iconv-lite typings are incorrect
smashercosmo opened this issue · comments
iconv-lite has just default export, but according to types it has named exports for every function.
correct types would be something like
declare module 'iconv-lite' {
interface IconvLite {
decode(buffer: Buffer, encoding: string, options?: Options): string;
encode(content: string, encoding: string, options?: Options): Buffer;
encodingExists(encoding: string): boolean;
// Stream API
decodeStream(encoding: string, options?: Options): NodeJS.ReadWriteStream;
encodeStream(encoding: string, options?: Options): NodeJS.ReadWriteStream;
// Low-level stream APIs
getEncoder(encoding: string, options?: Options): EncoderStream;
getDecoder(encoding: string, options?: Options): DecoderStream;
}
const lib: IconvLite
export default lib
}
A year or two ago there was some back and forth discussions about how to define iconv-lite types, see e.g. #149. As a result, we ended up with the current version and it seems to be working for the thousands of projects that use iconv-lite (including Angular AOT compiling, Electron and some other edge cases). I'd be reluctant to change it unless there's a significant problem.
What exactly the current version breaks for you?
Alright, I checked the code again and appeared that I was confused by this line iconv = module.exports;
On the second look, everything seems to be correct. And typescript doesn't yell at you). It was just IDE who was confused and for some reason couldn't resolve named exports and showed warnings about it.