typescript
TypeScript files: the strict compiler and the shipped lint and structure rules. It requires javascript. Guide: JavaScript and TypeScript.
Selected when
Section titled “Selected when”A scope has file extensions .ts, .tsx, .mts, or .cts, or a filename tsconfig.json. Also when nestjs or nextjs requires it.
Checks
Section titled “Checks”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.
What to do
Section titled “What to do”Fix the first error tsc prints; later errors often come from the same mistake.
Example
Section titled “Example”const count: number = "one"; reports an incompatible assignment. Assign a number, such as const count: number = 1;.
Turn it off
Section titled “Turn it off”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 overloadtsconfig
Section titled “tsconfig”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.
What to do
Section titled “What to do”Turn on the reported compiler option in your tsconfig.
Example
Section titled “Example”A tsconfig with strict set to false reports a finding. Set strict to true, and fix the new type errors.
Lint rules
Section titled “Lint rules”| 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. |
Turn it off
Section titled “Turn it off”gspot ignore typescript/tsconfig --paths "<path>" --reason "<why>"gspot ignore typescript/tsconfig --rule missing --reason "<why>"Lint rules turned off
Section titled “Lint rules turned off”| 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. |
Rules for coding agents
Section titled “Rules for coding agents”| Rule file | Installed when |
|---|---|
.gspot/rules/TYPESCRIPT.md |
Always |
Tools and versions
Section titled “Tools and versions”| Tool | Version |
|---|---|
| typescript-eslint | 8.71.2 |