typescript

A set of coding rules for TypeScript, a programming language that adds type checks to JavaScript. It covers type definitions, naming, safety, and function return types.

In plain words
What is it for?
Use it while writing or reviewing .ts, .tsx, .mts, or .cts files, especially when defining data shapes, public APIs, and reusable types.
Why use it?
It helps catch common mistakes before the code runs and keeps TypeScript code consistent across a project.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/jimmypocock/cursor-rules/typescript
Clone the repo
git clone --depth 1 https://github.com/jimmypocock/cursor-rules

Made for: Cursor.

Per session 4 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 753 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00004 $0.00753
Opus 5 $0.00002 $0.00377
Sonnet 5 $0.00001 $0.00151
Haiku 4.5 $0.00000 $0.00075

Measured yesterday against content hash cfb9beef8e13, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

typescript scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/typescript.mdc · 96 lines

How it starts

The opening of the file, as written. The whole thing — 96 lines — stays where its author put it; the contents beside it link to each section on GitHub.


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

Read the full file on GitHub · 96 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 96 lines · 4 tokens per session scan A cfb9beef8e13

Subscribe to this mod's changes

typescript is a cursor rule published in the GitHub repository jimmypocock/cursor-rules (8 stars, last pushed 1y ago), licensed MIT. It adds 4 tokens to every session and 753 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.