Skip to content

typescript

TypeScript files: the strict compiler and the shipped lint and structure rules. It requires javascript. Guide: JavaScript and TypeScript.

A scope has file extensions .ts, .tsx, .mts, or .cts, or a filename tsconfig.json. Also when nestjs or nextjs requires it.

Runs tsc on each tsconfig project, or on the TypeScript files of a scope that has no tsconfig, with the strict options of the level.

Runs at the push stage, once per scope, and needs the installed npm dependencies.

A type error left in a file can crash the program at run time, though the editor already showed it.

Fix the first error tsc prints; later errors often come from the same mistake.

const count: number = "one"; reports an incompatible assignment. Assign a number, such as const count: number = 1;.

gspot ignore typescript/tsc --paths "<path>" --reason "<why>"
gspot ignore typescript/tsc --rule <rule> --reason "<why>"

To silence one place, write a comment such as:

// @ts-expect-error reason: the library types omit this overload

Requires strict in every tsconfig you write. Level all also requires noUncheckedIndexedAccess, exactOptionalPropertyTypes, noImplicitOverride, noFallthroughCasesInSwitch, noImplicitReturns, and noPropertyAccessFromIndexSignature.

Runs at the commit stage.

One tsconfig that drops strict lets untyped code back in for that whole scope.

Turn on the reported compiler option in your tsconfig.

A tsconfig with strict set to false reports a finding. Set strict to true, and fix the new type errors.

Rule What it checks What to do
missing A scope with TypeScript files has a tsconfig.json. Create tsconfig.json in the scope folder; it can extend a shared tsconfig.
unreadable Each tsconfig of the scope loads, with every config that it extends. Install the package that the tsconfig extends, or correct the file. For a template that nobody installs, ignore its path with a reason.
strict strict is on. Set "strict": true under compilerOptions.
noUncheckedIndexedAccess At level all, noUncheckedIndexedAccess is on. Set "noUncheckedIndexedAccess": true under compilerOptions.
exactOptionalPropertyTypes At level all, exactOptionalPropertyTypes is on. Set "exactOptionalPropertyTypes": true under compilerOptions.
noImplicitOverride At level all, noImplicitOverride is on. Set "noImplicitOverride": true under compilerOptions.
noFallthroughCasesInSwitch At level all, noFallthroughCasesInSwitch is on. Set "noFallthroughCasesInSwitch": true under compilerOptions.
noImplicitReturns At level all, noImplicitReturns is on. Set "noImplicitReturns": true under compilerOptions.
noPropertyAccessFromIndexSignature At level all, noPropertyAccessFromIndexSignature is on. Set "noPropertyAccessFromIndexSignature": true under compilerOptions.
experimentalDecorators A NestJS scope turns experimentalDecorators on. Set "experimentalDecorators": true under compilerOptions.
emitDecoratorMetadata A NestJS scope turns emitDecoratorMetadata on. Set "emitDecoratorMetadata": true under compilerOptions.
alwaysStrict alwaysStrict stays on under strict. Remove "alwaysStrict": false from compilerOptions.
noImplicitAny noImplicitAny stays on under strict. Remove "noImplicitAny": false from compilerOptions.
noImplicitThis noImplicitThis stays on under strict. Remove "noImplicitThis": false from compilerOptions.
strictBindCallApply strictBindCallApply stays on under strict. Remove "strictBindCallApply": false from compilerOptions.
strictBuiltinIteratorReturn strictBuiltinIteratorReturn stays on under strict. Remove "strictBuiltinIteratorReturn": false from compilerOptions.
strictFunctionTypes strictFunctionTypes stays on under strict. Remove "strictFunctionTypes": false from compilerOptions.
strictNullChecks strictNullChecks stays on under strict. Remove "strictNullChecks": false from compilerOptions.
strictPropertyInitialization strictPropertyInitialization stays on under strict. Remove "strictPropertyInitialization": false from compilerOptions.
useUnknownInCatchVariables useUnknownInCatchVariables stays on under strict. Remove "useUnknownInCatchVariables": false from compilerOptions.
gspot ignore typescript/tsconfig --paths "<path>" --reason "<why>"
gspot ignore typescript/tsconfig --rule missing --reason "<why>"
Lint rules Files Why
@typescript-eslint/consistent-type-definitions **/*.d.ts TypeScript merges declarations through interfaces in declaration files.
import-x/no-default-export **/*.d.ts A declaration file describes the default export of its module.
Rule file Installed when
.gspot/rules/TYPESCRIPT.md Always
Tool Version
typescript-eslint 8.71.2