Configure TypeScript strictness: what `strict` includes (and is default in TypeScript 6), the extra checks it does not enable, and how to adopt them in an existing codebase.
.cursor/rules/typescript-strict-mode-configuration.mdc. Downloaded files need to be placed in that repository path.---
description: "Configure TypeScript strictness: what `strict` includes (and is default in TypeScript 6), the extra checks it does not enable, and how to adopt them in an existing codebase."
globs: "**/*"
alwaysApply: false
---
Apply these rules when configuring TypeScript compiler strictness.
## Baseline
- Set `"strict": true` in `tsconfig.json`. It enables the strict family: `noImplicitAny`, `strictNullChecks`, `strictFunctionTypes`, `strictBindCallApply`, `strictPropertyInitialization`, `strictBuiltinIteratorReturn`, `noImplicitThis`, `useUnknownInCatchVariables` and `alwaysStrict`. Do not list those individually as well unless you turn one off on purpose.
- TypeScript 6.0 made `strict` the default. Keep it explicit in `tsconfig.json` anyway so the intent survives compiler upgrades and tools that read the config.
## Extra checks not included in strict
```json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true
}
}
```
- `noUncheckedIndexedAccess`: indexing an array or record returns `T | undefined`, so missing elements must be handled.
- `exactOptionalPropertyTypes`: `prop?: string` no longer accepts an explicit `undefined`; write `prop?: string | undefined` where that is intended. Libraries' types may need updates before you enable it.
- `noImplicitReturns`, `noFallthroughCasesInSwitch`, `noImplicitOverride` catch common control-flow and inheritance mistakes.
## Adopting in an existing codebase
- Enable one flag at a time, fix or explicitly suppress the errors, and merge before the next flag. For large codebases, use a separate stricter tsconfig for new folders or a baseline tool, and run `tsc --noEmit` in CI.
## Type assertions
- Avoid `as` assertions and non-null `!` to silence the new errors; narrow with checks or fix the types. When an assertion is necessary, add a comment explaining why it is safe.
Cursor rules for Next.js 14+ App Router projects updated for Next.js 16 with async params, validated Route Handlers, generateMetadata and proxy.ts in place of middleware.
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Cursor
language
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Node service's tsconfig lists noImplicitAny, strictNullChecks and strictFunctionTypes individually without strict, and the team wants stricter indexing checks.
Apply the TypeScript Strict Mode Configuration rule to tsconfig.json and give a migration plan for noUncheckedIndexedAccess.
tsconfig uses strict: true instead of individual strict-family flags, adds noUncheckedIndexedAccess and the other extra checks one at a time, notes TypeScript 6's strict default, and fixes sample errors with narrowing instead of `!` or `as`.
Cursor applies project rules stored as .mdc files in .cursor/rules. Each rule's frontmatter (description, globs, alwaysApply) decides whether it is always included, attached to matching files, chosen by the agent from its description, or only used when you @-mention it. Cursor also reads AGENTS.md in the project root and subdirectories for plain-Markdown instructions.
.cursor/rules/typescript-strict-mode-configuration.mdcStarting point, not a tested configuration for your repository. Attached when files matching the globs are in context (alwaysApply: false with globs). Review the instructions, adapt the file paths and run your project's existing checks.
---
description: "TypeScript Strict Mode Configuration project conventions"
globs: "**/*"
alwaysApply: false
---
Apply these rules when configuring TypeScript compiler strictness.
## Baseline
- Set `"strict": true` in `tsconfig.json`. It enables the strict family: `noImplicitAny`, `strictNullChecks`, `strictFunctionTypes`, `strictBindCallApply`, `strictPropertyInitialization`, `strictBuiltinIteratorReturn`, `noImplicitThis`, `useUnknownInCatchVariables` and `alwaysStrict`. Do not list those individually as well unless you turn one off on purpose.
- TypeScript 6.0 made `strict` the default. Keep it explicit in `tsconfig.json` anyway so the intent survives compiler upgrades and tools that read the config.
## Extra checks not included in strict
```json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true
}
}
```
- `noUncheckedIndexedAccess`: indexing an array or record returns `T | undefined`, so missing elements must be handled.
- `exactOptionalPropertyTypes`: `prop?: string` no longer accepts an explicit `undefined`; write `prop?: string | undefined` where that is intended. Libraries' types may need updates before you enable it.
- `noImplicitReturns`, `noFallthroughCasesInSwitch`, `noImplicitOverride` catch common control-flow and inheritance mistakes.
## Adopting in an existing codebase
- Enable one flag at a time, fix or explicitly suppress the errors, and merge before the next flag. For large codebases, use a separate stricter tsconfig for new folders or a baseline tool, and run `tsc --noEmit` in CI.
## Type assertions
- Avoid `as` assertions and non-null `!` to silence the new errors; narrow with checks or fix the types. When an assertion is necessary, add a comment explaining why it is safe.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Cursor's docs recommend keeping individual rules under 500 lines and splitting large rules into composable ones. Cursor's documentation states that it supports AGENTS.md in the project root and in subdirectories. Use AGENTS.md for plain-Markdown instructions you also want other tools to read, and .mdc rules when you need Cursor's scoping options (globs, description-based selection, always-apply).
Documentation checked 2026-11-05: Cursor docs: Rules
Cursor rules for Next.js 14+ App Router projects updated for Next.js 16 with async params, validated Route Handlers, generateMetadata and proxy.ts in place of middleware.
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.