From fc79f2eea08910ba96226926dd2c3fee55020517 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Thu, 17 Sep 2020 17:48:36 -0400 Subject: [PATCH 1/4] feat: add skipLibCheck and forceConsistentCasingInFileNames - as defaults to the templates' tsconfigs - these are now recommended by TS to be set to true, which can be seen in the TSConfig Reference and @tsconfig/recommended - c.f. https://www.typescriptlang.org/tsconfig and https://www.npmjs.com/package/@tsconfig/recommended - also add to all fixtures - yea some centralization/extends or dogfooding create would help reduce all this duplication - skipLibCheck is a big perf gain, though it seems to only affect `tsc --noEmit` usage and rollup-plugin-typescript2 seems to ignore it - I have an existing issue open on the matter - forceConsistentCasingInFileNames is a no-brainer to help avoid a bug that is easy to make and hard to debug - also add a trailing comma for ease of use and better diffing - not to fixtures though, because there is a test for this --- templates/basic/tsconfig.json | 4 +++- templates/react-with-storybook/tsconfig.json | 4 +++- templates/react/tsconfig.json | 4 +++- test/e2e/fixtures/build-default/tsconfig.json | 4 +++- test/e2e/fixtures/build-invalid/tsconfig.json | 4 +++- test/e2e/fixtures/build-withTsconfig/tsconfig.base.json | 4 +++- test/integration/fixtures/build-options/tsconfig.json | 4 +++- test/integration/fixtures/build-withBabel/tsconfig.json | 4 +++- test/integration/fixtures/build-withConfig/tsconfig.json | 4 +++- 9 files changed, 27 insertions(+), 9 deletions(-) diff --git a/templates/basic/tsconfig.json b/templates/basic/tsconfig.json index 816d09263..e6945ffce 100644 --- a/templates/basic/tsconfig.json +++ b/templates/basic/tsconfig.json @@ -14,6 +14,8 @@ "noFallthroughCasesInSwitch": true, "moduleResolution": "node", "jsx": "react", - "esModuleInterop": true + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, } } diff --git a/templates/react-with-storybook/tsconfig.json b/templates/react-with-storybook/tsconfig.json index 816d09263..e6945ffce 100644 --- a/templates/react-with-storybook/tsconfig.json +++ b/templates/react-with-storybook/tsconfig.json @@ -14,6 +14,8 @@ "noFallthroughCasesInSwitch": true, "moduleResolution": "node", "jsx": "react", - "esModuleInterop": true + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, } } diff --git a/templates/react/tsconfig.json b/templates/react/tsconfig.json index 816d09263..e6945ffce 100644 --- a/templates/react/tsconfig.json +++ b/templates/react/tsconfig.json @@ -14,6 +14,8 @@ "noFallthroughCasesInSwitch": true, "moduleResolution": "node", "jsx": "react", - "esModuleInterop": true + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, } } diff --git a/test/e2e/fixtures/build-default/tsconfig.json b/test/e2e/fixtures/build-default/tsconfig.json index b25c2e554..ecd51ff3f 100644 --- a/test/e2e/fixtures/build-default/tsconfig.json +++ b/test/e2e/fixtures/build-default/tsconfig.json @@ -12,7 +12,9 @@ "noFallthroughCasesInSwitch": true, "moduleResolution": "node", "jsx": "react", - "esModuleInterop": true + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true }, "include": ["src", "types"] } diff --git a/test/e2e/fixtures/build-invalid/tsconfig.json b/test/e2e/fixtures/build-invalid/tsconfig.json index b25c2e554..ecd51ff3f 100644 --- a/test/e2e/fixtures/build-invalid/tsconfig.json +++ b/test/e2e/fixtures/build-invalid/tsconfig.json @@ -12,7 +12,9 @@ "noFallthroughCasesInSwitch": true, "moduleResolution": "node", "jsx": "react", - "esModuleInterop": true + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true }, "include": ["src", "types"] } diff --git a/test/e2e/fixtures/build-withTsconfig/tsconfig.base.json b/test/e2e/fixtures/build-withTsconfig/tsconfig.base.json index c5a66c1ea..81769b3fe 100644 --- a/test/e2e/fixtures/build-withTsconfig/tsconfig.base.json +++ b/test/e2e/fixtures/build-withTsconfig/tsconfig.base.json @@ -14,7 +14,9 @@ "noFallthroughCasesInSwitch": true, "moduleResolution": "node", "jsx": "react", - "esModuleInterop": false + "esModuleInterop": false, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true }, "include": ["src", "types"], // test parsing of trailing comma & comment } diff --git a/test/integration/fixtures/build-options/tsconfig.json b/test/integration/fixtures/build-options/tsconfig.json index 3645ceed5..804f4bd3e 100644 --- a/test/integration/fixtures/build-options/tsconfig.json +++ b/test/integration/fixtures/build-options/tsconfig.json @@ -12,7 +12,9 @@ "noFallthroughCasesInSwitch": true, "moduleResolution": "node", "jsx": "react", - "esModuleInterop": true + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true }, "include": ["src", "types"], } diff --git a/test/integration/fixtures/build-withBabel/tsconfig.json b/test/integration/fixtures/build-withBabel/tsconfig.json index 3645ceed5..804f4bd3e 100644 --- a/test/integration/fixtures/build-withBabel/tsconfig.json +++ b/test/integration/fixtures/build-withBabel/tsconfig.json @@ -12,7 +12,9 @@ "noFallthroughCasesInSwitch": true, "moduleResolution": "node", "jsx": "react", - "esModuleInterop": true + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true }, "include": ["src", "types"], } diff --git a/test/integration/fixtures/build-withConfig/tsconfig.json b/test/integration/fixtures/build-withConfig/tsconfig.json index 3645ceed5..804f4bd3e 100644 --- a/test/integration/fixtures/build-withConfig/tsconfig.json +++ b/test/integration/fixtures/build-withConfig/tsconfig.json @@ -12,7 +12,9 @@ "noFallthroughCasesInSwitch": true, "moduleResolution": "node", "jsx": "react", - "esModuleInterop": true + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true }, "include": ["src", "types"], } From 3e0fb159efc18fcdb0640dd57c6bf080d44cb196 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Thu, 17 Sep 2020 17:55:47 -0400 Subject: [PATCH 2/4] feat: add noEmit to templates' tsconfigs - for ease of use when using `tsc` for type-checking, which a lot of users already do - it doesn't fully type-check everything though, since we'd need to split off a tsconfig.build.json in order to let builds only run on `src` while type-checking would run on all files - but people already using `tsc --noEmit`, so might as well start supporting this as it's not uncommon - also add to all fixtures - yea some centralization/extends or dogfooding create would help reduce all this duplication --- templates/basic/tsconfig.json | 1 + templates/react-with-storybook/tsconfig.json | 1 + templates/react/tsconfig.json | 1 + test/e2e/fixtures/build-default/tsconfig.json | 3 ++- test/e2e/fixtures/build-invalid/tsconfig.json | 3 ++- test/e2e/fixtures/build-withTsconfig/tsconfig.base.json | 3 ++- test/integration/fixtures/build-options/tsconfig.json | 3 ++- test/integration/fixtures/build-withBabel/tsconfig.json | 3 ++- test/integration/fixtures/build-withConfig/tsconfig.json | 3 ++- 9 files changed, 15 insertions(+), 6 deletions(-) diff --git a/templates/basic/tsconfig.json b/templates/basic/tsconfig.json index e6945ffce..bda0c61e2 100644 --- a/templates/basic/tsconfig.json +++ b/templates/basic/tsconfig.json @@ -17,5 +17,6 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, + "noEmit": true, } } diff --git a/templates/react-with-storybook/tsconfig.json b/templates/react-with-storybook/tsconfig.json index e6945ffce..bda0c61e2 100644 --- a/templates/react-with-storybook/tsconfig.json +++ b/templates/react-with-storybook/tsconfig.json @@ -17,5 +17,6 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, + "noEmit": true, } } diff --git a/templates/react/tsconfig.json b/templates/react/tsconfig.json index e6945ffce..bda0c61e2 100644 --- a/templates/react/tsconfig.json +++ b/templates/react/tsconfig.json @@ -17,5 +17,6 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, + "noEmit": true, } } diff --git a/test/e2e/fixtures/build-default/tsconfig.json b/test/e2e/fixtures/build-default/tsconfig.json index ecd51ff3f..d0dea9704 100644 --- a/test/e2e/fixtures/build-default/tsconfig.json +++ b/test/e2e/fixtures/build-default/tsconfig.json @@ -14,7 +14,8 @@ "jsx": "react", "esModuleInterop": true, "skipLibCheck": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "noEmit": true }, "include": ["src", "types"] } diff --git a/test/e2e/fixtures/build-invalid/tsconfig.json b/test/e2e/fixtures/build-invalid/tsconfig.json index ecd51ff3f..d0dea9704 100644 --- a/test/e2e/fixtures/build-invalid/tsconfig.json +++ b/test/e2e/fixtures/build-invalid/tsconfig.json @@ -14,7 +14,8 @@ "jsx": "react", "esModuleInterop": true, "skipLibCheck": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "noEmit": true }, "include": ["src", "types"] } diff --git a/test/e2e/fixtures/build-withTsconfig/tsconfig.base.json b/test/e2e/fixtures/build-withTsconfig/tsconfig.base.json index 81769b3fe..639f22f26 100644 --- a/test/e2e/fixtures/build-withTsconfig/tsconfig.base.json +++ b/test/e2e/fixtures/build-withTsconfig/tsconfig.base.json @@ -16,7 +16,8 @@ "jsx": "react", "esModuleInterop": false, "skipLibCheck": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "noEmit": true }, "include": ["src", "types"], // test parsing of trailing comma & comment } diff --git a/test/integration/fixtures/build-options/tsconfig.json b/test/integration/fixtures/build-options/tsconfig.json index 804f4bd3e..bb0179011 100644 --- a/test/integration/fixtures/build-options/tsconfig.json +++ b/test/integration/fixtures/build-options/tsconfig.json @@ -14,7 +14,8 @@ "jsx": "react", "esModuleInterop": true, "skipLibCheck": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "noEmit": true }, "include": ["src", "types"], } diff --git a/test/integration/fixtures/build-withBabel/tsconfig.json b/test/integration/fixtures/build-withBabel/tsconfig.json index 804f4bd3e..547e772e3 100644 --- a/test/integration/fixtures/build-withBabel/tsconfig.json +++ b/test/integration/fixtures/build-withBabel/tsconfig.json @@ -14,7 +14,8 @@ "jsx": "react", "esModuleInterop": true, "skipLibCheck": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "noEmit": false }, "include": ["src", "types"], } diff --git a/test/integration/fixtures/build-withConfig/tsconfig.json b/test/integration/fixtures/build-withConfig/tsconfig.json index 804f4bd3e..bb0179011 100644 --- a/test/integration/fixtures/build-withConfig/tsconfig.json +++ b/test/integration/fixtures/build-withConfig/tsconfig.json @@ -14,7 +14,8 @@ "jsx": "react", "esModuleInterop": true, "skipLibCheck": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "noEmit": true }, "include": ["src", "types"], } From 4346bbabff3c3f3d3e3d67d708e9ec1031cefb55 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Thu, 17 Sep 2020 18:11:51 -0400 Subject: [PATCH 3/4] docs: add comments for nearly all tsconfig options in use - since we can use comments in tsconfig.json, add them to give simple, one-liner explanations as to what each setting does - also add a link to the TSConfig Reference for further details - and specify which options are recommended as true by TS but not on by default for backwards compat or other reasons - a few leftover that I still need to think about --- templates/basic/tsconfig.json | 12 ++++++++++++ templates/react-with-storybook/tsconfig.json | 12 ++++++++++++ templates/react/tsconfig.json | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/templates/basic/tsconfig.json b/templates/basic/tsconfig.json index bda0c61e2..441afb11c 100644 --- a/templates/basic/tsconfig.json +++ b/templates/basic/tsconfig.json @@ -1,22 +1,34 @@ { + // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs "include": ["src", "types"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], "importHelpers": true, + // output .d.ts declaration files for consumers "declaration": true, + // output .js.map sourcemap files for consumers "sourceMap": true, + // match output dir to input dir. e.g. dist/index instead of dist/src/index "rootDir": "./src", + // stricter type-checking for stronger correctness. Recommended by TS "strict": true, + // linter checks for common issues "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + // use Node's module resolution algorithm, instead of the legacy TS one "moduleResolution": "node", + // transpile JSX to React.createElement "jsx": "react", + // interop between ESM and CJS modules. Recommended by TS "esModuleInterop": true, + // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS "skipLibCheck": true, + // error out if import and file system have a casing mismatch. Recommended by TS "forceConsistentCasingInFileNames": true, + // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` "noEmit": true, } } diff --git a/templates/react-with-storybook/tsconfig.json b/templates/react-with-storybook/tsconfig.json index bda0c61e2..441afb11c 100644 --- a/templates/react-with-storybook/tsconfig.json +++ b/templates/react-with-storybook/tsconfig.json @@ -1,22 +1,34 @@ { + // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs "include": ["src", "types"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], "importHelpers": true, + // output .d.ts declaration files for consumers "declaration": true, + // output .js.map sourcemap files for consumers "sourceMap": true, + // match output dir to input dir. e.g. dist/index instead of dist/src/index "rootDir": "./src", + // stricter type-checking for stronger correctness. Recommended by TS "strict": true, + // linter checks for common issues "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + // use Node's module resolution algorithm, instead of the legacy TS one "moduleResolution": "node", + // transpile JSX to React.createElement "jsx": "react", + // interop between ESM and CJS modules. Recommended by TS "esModuleInterop": true, + // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS "skipLibCheck": true, + // error out if import and file system have a casing mismatch. Recommended by TS "forceConsistentCasingInFileNames": true, + // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` "noEmit": true, } } diff --git a/templates/react/tsconfig.json b/templates/react/tsconfig.json index bda0c61e2..441afb11c 100644 --- a/templates/react/tsconfig.json +++ b/templates/react/tsconfig.json @@ -1,22 +1,34 @@ { + // see https://www.typescriptlang.org/tsconfig to better understand tsconfigs "include": ["src", "types"], "compilerOptions": { "module": "esnext", "lib": ["dom", "esnext"], "importHelpers": true, + // output .d.ts declaration files for consumers "declaration": true, + // output .js.map sourcemap files for consumers "sourceMap": true, + // match output dir to input dir. e.g. dist/index instead of dist/src/index "rootDir": "./src", + // stricter type-checking for stronger correctness. Recommended by TS "strict": true, + // linter checks for common issues "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + // use Node's module resolution algorithm, instead of the legacy TS one "moduleResolution": "node", + // transpile JSX to React.createElement "jsx": "react", + // interop between ESM and CJS modules. Recommended by TS "esModuleInterop": true, + // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS "skipLibCheck": true, + // error out if import and file system have a casing mismatch. Recommended by TS "forceConsistentCasingInFileNames": true, + // `tsdx build` ignores this option, but it is commonly used when type-checking separately with `tsc` "noEmit": true, } } From d8f95800d33cd0431814d52146be191fd6a74656 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Thu, 17 Sep 2020 18:20:31 -0400 Subject: [PATCH 4/4] docs: add comment that noUnused* overlaps with an ESLint rule - the checks overlap with the @typescript-eslint/no-unused-vars rule - per user issue, this can result in duplicative errors inside an IDE, so explicitly call this out in a comment for `tsdx lint` / ESLint users in case they'd like to disable this and leave only one on - change the ordering of linter checks in the templates as well to make the comments easier to read/understand --- templates/basic/tsconfig.json | 5 +++-- templates/react-with-storybook/tsconfig.json | 5 +++-- templates/react/tsconfig.json | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/templates/basic/tsconfig.json b/templates/basic/tsconfig.json index 441afb11c..2c85b2d99 100644 --- a/templates/basic/tsconfig.json +++ b/templates/basic/tsconfig.json @@ -14,10 +14,11 @@ // stricter type-checking for stronger correctness. Recommended by TS "strict": true, // linter checks for common issues - "noUnusedLocals": true, - "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative + "noUnusedLocals": true, + "noUnusedParameters": true, // use Node's module resolution algorithm, instead of the legacy TS one "moduleResolution": "node", // transpile JSX to React.createElement diff --git a/templates/react-with-storybook/tsconfig.json b/templates/react-with-storybook/tsconfig.json index 441afb11c..2c85b2d99 100644 --- a/templates/react-with-storybook/tsconfig.json +++ b/templates/react-with-storybook/tsconfig.json @@ -14,10 +14,11 @@ // stricter type-checking for stronger correctness. Recommended by TS "strict": true, // linter checks for common issues - "noUnusedLocals": true, - "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative + "noUnusedLocals": true, + "noUnusedParameters": true, // use Node's module resolution algorithm, instead of the legacy TS one "moduleResolution": "node", // transpile JSX to React.createElement diff --git a/templates/react/tsconfig.json b/templates/react/tsconfig.json index 441afb11c..2c85b2d99 100644 --- a/templates/react/tsconfig.json +++ b/templates/react/tsconfig.json @@ -14,10 +14,11 @@ // stricter type-checking for stronger correctness. Recommended by TS "strict": true, // linter checks for common issues - "noUnusedLocals": true, - "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + // noUnused* overlap with @typescript-eslint/no-unused-vars, can disable if duplicative + "noUnusedLocals": true, + "noUnusedParameters": true, // use Node's module resolution algorithm, instead of the legacy TS one "moduleResolution": "node", // transpile JSX to React.createElement