Skip to content

Commit

Permalink
chore(tsconfig): simplify tsconfig strict config
Browse files Browse the repository at this point in the history
We should be opting *into* strict mode and only opting *out* of some flags incrementally
while we fix errors.

This commit:
- flips the global `strict` on
- removes values being set to the default via the above
- stops disabling flags that obscured no errors (or very few, which I then fixed)
- moves a few flag disablings to the specific packages that require it
- explictly configures strict flags for already rather strict packages
  • Loading branch information
serhalp committed Feb 27, 2025
1 parent 698febd commit 46a428d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 23 deletions.
3 changes: 2 additions & 1 deletion packages/build/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "lib" /* Specify an output folder for all emitted files. */
"outDir": "lib" /* Specify an output folder for all emitted files. */,
"strictBindCallApply": false /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
},
"include": ["src/**/*.js", "src/**/*.ts"],
"exclude": ["tests/**"]
Expand Down
3 changes: 2 additions & 1 deletion packages/nock-udp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "lib" /* Specify an output folder for all emitted files. */
"outDir": "lib" /* Specify an output folder for all emitted files. */,
"strictBindCallApply": false /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
},
"include": ["src/**/*.js", "src/**/*.ts"],
"exclude": ["test/**"]
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/src/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class Fixture {
async runDev(devCommand: unknown): Promise<string> {
const entryPoint = startDev.bind(null, devCommand)
const { logs } = await entryPoint(this.getBuildFlags())
return [logs.stdout.join('\n'), logs.stderr.join('\n')].filter(Boolean).join('\n\n')
return [logs?.stdout.join('\n'), logs?.stderr.join('\n')].filter(Boolean).join('\n\n')
}

/** use the CLI entry point instead of the Node.js main function */
Expand Down
3 changes: 2 additions & 1 deletion packages/testing/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "lib" /* Specify an output folder for all emitted files. */
"outDir": "lib" /* Specify an output folder for all emitted files. */,
"strictBindCallApply": false /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
},
"include": ["src/**/*.ts"]
}
2 changes: 2 additions & 0 deletions packages/zip-it-and-ship-it/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { promises as fs } from 'fs'
import { basename, extname, dirname, join } from 'path'

import isPathInside from 'is-path-inside'
// @ts-expect-error(serhalp) -- Remove once https://github.com/schnittstabil/merge-options/pull/28 is merged, or replace
// this dependency.
import mergeOptions from 'merge-options'
import { z } from 'zod'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { dirname } from 'path'

import type { ArgumentPlaceholder, Expression, SpreadElement, JSXNamespacedName } from '@babel/types'
// @ts-expect-error(serhalp) -- Remove once https://github.com/schnittstabil/merge-options/pull/28 is merged, or replace
// this dependency.
import mergeOptions from 'merge-options'
import { z } from 'zod'

Expand Down
10 changes: 9 additions & 1 deletion packages/zip-it-and-ship-it/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
"compilerOptions": {
"outDir": "dist" /* Specify an output folder for all emitted files. */,
"esModuleInterop": true,
"strict": true
"noImplicitAny": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"useUnknownInCatchVariables": false,
"exactOptionalPropertyTypes": false,
"noImplicitReturns": false,
"noUncheckedIndexedAccess": false,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": false
},
"include": ["src"],
"exclude": ["tests/**"]
Expand Down
19 changes: 1 addition & 18 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */

/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
Expand All @@ -23,7 +21,6 @@
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "NodeNext" /* Specify what module code is generated. */,
// "rootDir": "./" /* Specify the root folder within your source files. */,
Expand All @@ -39,12 +36,10 @@
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

/* JavaScript Support */
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */

/* Emit */
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
Expand All @@ -69,36 +64,24 @@
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

/* Type Checking */
/* REMOVE THOSE ALL ONCE WE HAVE HANDCRAFTED TYPES */
"strict": false /* Enable all strict type-checking options. */,
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": false /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
"strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
"strictFunctionTypes": false /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
"strictBindCallApply": false /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */,
"strictPropertyInitialization": false /* Check for class properties that are declared but not set in the constructor. */,
"noImplicitThis": true /* Enable error reporting when 'this' is given the type 'any'. */,
"useUnknownInCatchVariables": false /* Default catch clause variables as 'unknown' instead of 'any'. */,
"alwaysStrict": false /* Ensure 'use strict' is always emitted. */,
"noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
"noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
"exactOptionalPropertyTypes": false /* Interpret optional property types as written, rather than adding 'undefined'. */,
"noImplicitReturns": false /* Enable error reporting for codepaths that do not explicitly return in a function. */,
"noFallthroughCasesInSwitch": false /* Enable error reporting for fallthrough cases in switch statements. */,
"noUncheckedIndexedAccess": false /* Add 'undefined' to a type when accessed using an index. */,
"noImplicitOverride": false /* Ensure overriding members in derived classes are marked with an override modifier. */,
"noPropertyAccessFromIndexSignature": false /* Enforces using indexed accessors for keys declared using an indexed type. */,
"allowUnusedLabels": false /* Disable error reporting for unused labels. */,
"allowUnreachableCode": false /* Disable error reporting for unreachable code. */,

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
Expand Down

0 comments on commit 46a428d

Please sign in to comment.