Windsurf rules for strict TypeScript: strict plus extra index and optional-property checks, interfaces and unions, keyof generics, sound type guards and branded IDs.
.devin/rules/typescript-strict-guidelines.md. Downloaded files need to be placed in that repository path.---
trigger: glob
globs: "**/*"
---
Apply these rules to TypeScript code.
## Strict configuration
Enable in tsconfig.json:
- `strict: true` (default since TypeScript 6.0; keep it explicit)
- `noUncheckedIndexedAccess: true` (not part of strict)
- `exactOptionalPropertyTypes: true` (not part of strict)
## Type patterns
```ts
// Object shapes
interface User {
id: string;
email: string;
role: 'admin' | 'user';
}
// Unions and derived types
type UserRole = User['role'];
type UserPatch = Partial<Omit<User, 'id'>>;
// Generic constraint: key must exist on the object
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
// Type guard that checks the property types it promises
function isUser(value: unknown): value is User {
if (typeof value !== 'object' || value === null) return false;
const v = value as Record<string, unknown>;
return (
typeof v.id === 'string' &&
typeof v.email === 'string' &&
(v.role === 'admin' || v.role === 'user')
);
}
```
## Best practices
- Never use `any`; use `unknown` for truly unknown values and narrow them.
- Model state machines as discriminated unions (`{ status: 'loading' } | { status: 'error'; message: string } | ...`).
- Use the built-in utility types (`Partial`, `Required`, `Pick`, `Omit`, `Record`) instead of rewriting them.
- Create branded types for IDs that must not be mixed (`type UserId = string & { readonly __brand: 'UserId' }`), constructed in one function.
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Copilot instructions for TypeScript project setup covering strict tsconfig flags and their effects, type-only imports, module hygiene and TSDoc for public APIs.
Windsurf
general
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Windsurf TypeScript project's isUser guard returns true for any object with an email key, letting malformed API data through.
Tighten src/types/user.ts and src/guards.ts following the TypeScript strict guidelines rule.
isUser checks id, email and role types; UserPatch is derived with Partial<Omit<...>>; IDs that must not mix get branded types with a constructor; tsconfig has strict plus noUncheckedIndexedAccess and exactOptionalPropertyTypes.
Windsurf's rules documentation (docs.windsurf.com/windsurf/cascade/memories) now redirects to Devin documentation, which describes rules for the Devin Local agent in Devin Desktop. Current rules live in .devin/rules/*.md with a trigger setting, and the legacy Windsurf files (.windsurf/rules/*.md, .windsurf/global_rules.md and .windsurfrules) are still imported by default. AGENTS.md files are read as always-on rules.
.devin/rules/typescript-strict-guidelines.mdStarting point, not a tested configuration for your repository. Applied when files matching globs are involved (trigger: glob). Review the instructions, adapt the file paths and run your project's existing checks.
---
trigger: glob
globs: "**/*"
---
Apply these rules to TypeScript code.
## Strict configuration
Enable in tsconfig.json:
- `strict: true` (default since TypeScript 6.0; keep it explicit)
- `noUncheckedIndexedAccess: true` (not part of strict)
- `exactOptionalPropertyTypes: true` (not part of strict)
## Type patterns
```ts
// Object shapes
interface User {
id: string;
email: string;
role: 'admin' | 'user';
}
// Unions and derived types
type UserRole = User['role'];
type UserPatch = Partial<Omit<User, 'id'>>;
// Generic constraint: key must exist on the object
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
// Type guard that checks the property types it promises
function isUser(value: unknown): value is User {
if (typeof value !== 'object' || value === null) return false;
const v = value as Record<string, unknown>;
return (
typeof v.id === 'string' &&
typeof v.email === 'string' &&
(v.role === 'admin' || v.role === 'user')
);
}
```
## Best practices
- Never use `any`; use `unknown` for truly unknown values and narrow them.
- Model state machines as discriminated unions (`{ status: 'loading' } | { status: 'error'; message: string } | ...`).
- Use the built-in utility types (`Partial`, `Required`, `Pick`, `Omit`, `Record`) instead of rewriting them.
- Create branded types for IDs that must not be mixed (`type UserId = string & { readonly __brand: 'UserId' }`), constructed in one function.
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.
The docs recommend keeping rules short and specific. The current docs say AGENTS.md, AGENTS.local.md and AGENT.md are read as always-on rules, including files in subdirectories. Use .devin/rules/ when you need glob, model-decision or manual triggers.
Documentation checked 2026-11-05: Devin docs: Local customizations (redirect target of Windsurf memories docs)Windsurf docs: Cascade memories (redirects)
Cursor rules for strict TypeScript: compiler checks beyond strict, interfaces vs type aliases, real type guards, discriminated unions, utility types and branded IDs.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Copilot instructions for TypeScript project setup covering strict tsconfig flags and their effects, type-only imports, module hygiene and TSDoc for public APIs.