cloudflare / cloudflare/worker-typescript-template

Redundant configurations in tsconfig.json?

Open
#29 2 comments 7 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
447
Forks
93
PR merge metrics
No merged PRs in 30d

Description

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](https://www.typescriptlang.org/tsconfig#exclude)). 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](https://www.typescriptlang.org/tsconfig#types)). 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](https://github.com/vincentpun/worker-typescript-template/tree/tsconfig-fixes)) and ready for a PR, but I just wanted to open this issue to make sure my line of thought is correct.

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.