worker-typescript-template
worker-typescript-template copied to clipboard
Redundant configurations in tsconfig.json?
Hi, I was using this project to build a worker on Cloudflare. I was trying to add @types/mocha but noticed that I had to add every global declaration I installed to compilerOptions.types in TSConfig. After some investigation, I believe there are possible redundant configurations in the file:
-
The
excludeproperty is only necessary if you want to exclude files or directories that are included using theincludeproperty (See TypeScript TSConfig Reference). The original specified directories in theexcludeproperty, namelynode_modulesanddist, are not covered ininclude, so it's redundant. -
Since
./node_modules/@cloudflare/workers-types/index.d.tsis included in theincludeproperty, but then excluded as the wholenode_modulesdirectory is excluded (as specified in theexcludeproperty), I suspect that the typing information did not work and hence a fix was attempted by adding@cloudflare/workers-typestocompilerOptions.types. -
Unfortunately, adding
compilerOptions.typeswill cause TypeScript to only use global declarations in the specified folders (See TypeScript TSConfig Reference). As a result, all global declarations elsewhere (notably,./node_modules/@types) are now completely ignored, so I had to manually addmochatocompilerOptions.types.
As this is a batteries-included template, I should expect most things to work relatively similar to the most common use-case, that is, installing @types packages should work immediately without tinkering with the compilerOptions.types property.
I have a fix in my own fork (tsconfig-fixes branch) and ready for a PR, but I just wanted to open this issue to make sure my line of thought is correct.
Thanks!
LGTM. Could make sense to have this merged @signalnerve :)
Looks like this is still relevant, any reason not to open and merge the PR?