cloudflare/worker-typescript-template

Redundant configurations in tsconfig.json?

vincentpun opened this issue · 2 comments

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:

  1. The exclude property is only necessary if you want to exclude files or directories that are included using the include property (See TypeScript TSConfig Reference). The original specified directories in the exclude property, namely node_modules and dist, are not covered in include, so it's redundant.

  2. Since ./node_modules/@cloudflare/workers-types/index.d.ts is included in the include property, but then excluded as the whole node_modules directory is excluded (as specified in the exclude property), I suspect that the typing information did not work and hence a fix was attempted by adding @cloudflare/workers-types to compilerOptions.types.

  3. Unfortunately, adding compilerOptions.types will 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 add mocha to compilerOptions.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?