jszip
jszip copied to clipboard
Typescript typings error caused by inclusion of NodeJS typings
I updated to your latest version and noticed I got some typing errors. After some investigation I noticed you added typescript typings between version 3.2.x and 3.4.x. The new typing file (index.d.ts) included the following line
/// <reference types="node" />
Which includes all NodeJS typings when using jszip in typescript. Not really the desired behavior when using jszip in the browser instead of in NodeJS.
It causes errors like:
ERROR in node_modules/@types/node/index.d.ts(139,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type 'any', but here has type 'NodeRequire'.
I don't know why you include the NodeJS typings, but can you either not include it and use interfaces for the typings you need, or have 2 separate typings, one for NodeJS and one for the browser?
Thanks for filing this issue. The reason Node typings are included are because the inputs and outputs can take Node's ReadableStream
and Buffer
.
I can't see a way to provide browser and Node typings without requiring configuration from the consumer. Do you know of a way?
Good question, normally you would import specific types like
import { ReadableStream, Buffer } from "@types/node"
But since node uses ambient declarations I am not sure if that it at all possible. You can always copy the typings over and use them. What I did myself was just remove the typings and be fine.
Another thing you can do is don't package typings with your package and use the DefinitelyTyped project to export 2 different kind of typings, one for node and one for browsers.
Another Problem: internalStream (https://stuk.github.io/jszip/documentation/api_zipobject/internal_stream.html) is missing in the index.d.ts file?
@blackshadev just wondering, do you define the type of require
yourself in your project, instead of using Node's require?
The error you posted seems to indicate that require
is being defined twice.
@killerfurbel could you file a new issue? (I also have limited time at the moment, so if you could create a PR to fix it then I'd really appreciate that!)
@Stuk Yeah, I have my "own" require and timeout definitions because I don't use NodeJS, but the browser with webpack. The typings of webpack+browser is a bit different than NodeJS.
so, is there any solution to this problem? My setTimeout definition has been overwritten with export function setTimeout<[]>( callback: () => void, ms?: number | undefined): NodeJS.Timeout
so, is there any solution to this problem? My setTimeout definition has been overwritten with
export function setTimeout<[]>( callback: () => void, ms?: number | undefined): NodeJS.Timeout
+1. Same problem here. Guess I will need to find something else for replacement.