agentleFS
jimmypocockjimmypocock/cursor-rules/.cursor/rules/typescript.mdc

cursor-rules / rules

Cursor rule8 starsChanged 19 months agoMITView on GitHub

TypeScript Development Standards

The file

Show its rules and text

We split this typescript.mdc into the rules it gives an agent

35 rules. About 0 are common, 24 are distinctive, and 11 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈24

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 11

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Avoid using any type unless absolutely necessary

    line 16
  2. Distinctive:

    Use type inference where it improves readability

    line 17
  3. Distinctive:

    Create reusable type definitions for common patterns

    line 19
  4. Very specific:

    Use PascalCase for interface and type names (e.g., UserProfile)

    line 25
  5. Very specific:

    Use descriptive names that convey purpose (e.g., ApiResponse rather than just Response)

    line 27
  6. Very specific:

    Avoid prefixing interfaces with 'I' (prefer User over IUser)

    line 28
  7. Distinctive:

    Use interfaces for object shapes primarily

    line 31
  8. Distinctive:

    Use type aliases for unions, intersections, or complex types

    line 32
  9. Distinctive:

    Prefer interfaces for public APIs to support declaration merging

    line 33
  10. Distinctive:

    Keep type definitions close to where they are used

    line 34
  11. Very specific:

    Use unknown instead of any when type is unclear

    line 39
  12. Distinctive:

    Use union types to represent values that could be of different types

    line 40
  13. Distinctive:

    Add appropriate type guards when narrowing types

    line 42
  14. Very specific:

    Use readonly modifiers for immutable properties

    line 43
  15. Very specific:

    Use as const for literal values when appropriate

    line 44
  16. Very specific:

    Use optional chaining (?.) to safely access nested properties

    line 49
  17. Very specific:

    Use nullish coalescing (??) to provide default values

    line 50
  18. Distinctive:

    Use template literal types for string manipulations

    line 51
  19. Distinctive:

    Use conditional types for type-level programming

    line 53
  20. Distinctive:

    Use const assertions for readonly arrays and tuples

    line 55
  21. Distinctive:

    Create and use custom error types

    line 58
  22. Distinctive:

    Use discriminated unions for type-safe error handling

    line 59
  23. Very specific:

    Prefer arrow functions for consistent this binding

    line 63
  24. Distinctive:

    Use function overloads for functions with complex type relationships

    line 64
  25. Distinctive:

    Use rest parameters instead of arguments object

    line 65
  26. Distinctive:

    Use async/await over Promise chains

    line 70
  27. Distinctive:

    Use Promise.all/allSettled for parallel operations

    line 73
  28. Distinctive:

    Use path aliases to simplify imports

    line 77
  29. Distinctive:

    Use ES modules with named exports

    line 82
  30. Distinctive:

    Document complex types with JSDoc/TSDoc comments

    line 88
  31. Distinctive:

    Document constraints and invariants that types enforce

    line 90
  32. Very specific:

    Use @deprecated tags when phasing out types

    line 91
  33. Distinctive:

    Use type-aware testing frameworks

    line 94
  34. Distinctive:

    Test type constraints with compile-time tests

    line 95
  35. Distinctive:

    Ensure tests cover edge cases in type handling

    line 96

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
typescript.mdc
---
description: TypeScript Development Standards
globs: 
alwaysApply: false
---
---
Description: TypeScript Development Standards
Globs: **/*.ts, **/*.tsx, **/*.mts, **/*.cts
---

# TypeScript Development Standards
@base.mdc

## Core TypeScript Principles
- Leverage TypeScript's static typing to catch errors at compile time
- Avoid using `any` type unless absolutely necessary
- Use type inference where it improves readability
- Define explicit return types for functions
- Create reusable type definitions for common patterns
- Take advantage of TypeScript's advanced type features when appropriate

## Type Definitions

### Naming
- Use PascalCase for interface and type names (e.g., `UserProfile`)
- Prefix interfaces for React component props with component name (e.g., `ButtonProps`)
- Use descriptive names that convey purpose (e.g., `ApiResponse` rather than just `Response`)
- Avoid prefixing interfaces with 'I' (prefer `User` over `IUser`)

### Structure
- Use interfaces for object shapes primarily
- Use type aliases for unions, intersections, or complex types
- Prefer interfaces for public APIs to support declaration merging
- Keep type definitions close to where they are used
- Export types that are used across multiple files

### Type Safety
- Enable strict type checking in `tsconfig.json`
- Use `unknown` instead of `any` when type is unclear
- Use union types to represent values that could be of different types
- Utilize generics for flexible, reusable code
- Add appropriate type guards when narrowing types
- Use `readonly` modifiers for immutable properties
- Use `as const` for literal values when appropriate

## Best Practices

### Modern TypeScript Features
- Use optional chaining (`?.`) to safely access nested properties
- Use nullish coalescing (`??`) to provide default values
- Use template literal types for string manipulations
- Apply mapped types to transform existing types
- Use conditional types for type-level programming
- Leverage utility types (e.g., `Partial<T>`, `Required<T>`, `Pick<T>`, `Omit<T>`)
- Use const assertions for readonly arrays and tuples

### Error Handling
- Create and use custom error types 
- Use discriminated unions for type-safe error handling
- Implement Result types for functions that can fail

### Functions
- Prefer arrow functions for consistent `this` binding
- Use function overloads for functions with complex type relationships
- Use rest parameters instead of arguments object
- Destructure objects in function parameters for clarity
- Provide explicit return types for non-trivial functions

### Async Code
- Use async/await over Promise chains
- Properly type Promise results
- Handle errors in async functions with try/catch
- Use Promise.all/allSettled for parallel operations

## Environment Configuration
- Set appropriate target and lib settings in tsconfig.json
- Use path aliases to simplify imports
- Enable incremental compilation for larger projects
- Configure appropriate module resolution

## Organizing Code
- Use ES modules with named exports
- Group related types in namespaces or dedicated type files
- Organize code with barrel files (index.ts) for cleaner imports
- Split complex types into smaller, composed types

## Documentation
- Document complex types with JSDoc/TSDoc comments
- Include examples for non-obvious type usage
- Document constraints and invariants that types enforce
- Use `@deprecated` tags when phasing out types

## Testing
- Use type-aware testing frameworks
- Test type constraints with compile-time tests
- Ensure tests cover edge cases in type handling

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.