As part of the migration to typescript, jest-util now has a dependency on @types/node.
This creates issues with code that will be written in a consuming TypeScript application, since some function types are modified (e.g. setTimeout). You can see more comments on similar issues here: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/21310
I propose to remove the @types/node dependency from the jest-util package, in order to not affect any code that is written by the user.
I was afraid something like this would be an issue. It's really unfortunate that TS allows the global namespace to be polluted by dependencies of dependencies
I propose to remove the @types/node dependency from the jest-util package, in order to not affect any code that is written by the user.
Then jest-util will not be consumable in TS since it will reference types that do not exist. How does other packages resolve this?
How about having the types as a peer or optional dependency
@SimenB Isn't the @types/node supposed to be in devDependencies? Not 100% sure but I believe it will be OK as soon as the packaged version of the jest-util package is the transpiled one
If Jest's public API (the compiled declaration files) rely on @types/node, then it must be a dependency, otherwise it can be a dev dependency. Otherwise, this forces the consumer to install @types/node manually, which non-TS users shoudn't have to do.
I believe that, in the case where jest-util uses types from the @types in its d.ts, going for peerDependencies or opt ones might be the right thing to do. In a way, types are only needed for TS users and are not really runtime constraints but just dev contraints.
EDIT
RXJS choice is to put it inside devDependencies:
https://github.com/ReactiveX/rxjs/blob/master/package.json
If you use rxjs with TypeScript you need to manually add @types/node to your package.json otherwise you will get error stacks as soon as you import it from a TypeScript file.
Yeah, I think we'll do that as well. Sindre Sorhus does the same thing when adding typings now. The error TSC throws is pretty clear. Anybody wanna send a PR? We can just add @types/node to the root package.json and remove it from the individual packages.
Note that this is _just_ @types/node, all other @types/* should remain
Hi @SimenB,
out of curiosity, can you clarify which approach you would like to take? dubzzz's proposal?
@types/node should only be in the package.json in the root of the repo, nowhere else
Do you mean in devDependencies? Like rxjs does.
The root package.json is private, so it doesn't matter if it's dev or not. It's never published
Is there a plan to publish a new jest version which includes this change?
There'll be a release next week