typescript-patterns

typescript-patterns is a cursor rule for Cursor from lambda-curry/medusa2-starter. It costs 2,969 tokens per session, scanned A, original, MIT.

A set of TypeScript development rules for a Medusa monorepo, including type definitions, type guards, unions, interfaces, and strict configuration. TypeScript is JavaScript with optional checks that catch many type mistakes before runtime.

In plain words
What is it for?
Use it when writing or reviewing TypeScript types, API response shapes, validation logic, and reusable generic code.
Why use it?
It gives contributors consistent ways to describe data and reduce type-related errors across the codebase.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when writing or reviewing TypeScript types, API response shapes, validation logic, and reusable generic code.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/lambda-curry/medusa2-starter/typescript-patterns
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.

Clone the repo
git clone --depth 1 https://github.com/lambda-curry/medusa2-starter

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for typescript-patterns

README.md
[![agentmods](https://agentmods.dev/badge/rules/lambda-curry/medusa2-starter/typescript-patterns/github.svg)](https://agentmods.dev/rules/lambda-curry/medusa2-starter/typescript-patterns)
Your own site
<a href="https://agentmods.dev/rules/lambda-curry/medusa2-starter/typescript-patterns"><img src="https://agentmods.dev/badge/rules/lambda-curry/medusa2-starter/typescript-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for typescript-patterns

Your own site · 80×15
<a href="https://agentmods.dev/rules/lambda-curry/medusa2-starter/typescript-patterns"><img src="https://agentmods.dev/badge/rules/lambda-curry/medusa2-starter/typescript-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 2,969 This file is loaded in full into every session.
When invoked 2,969 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.02969 $0.02969
Opus 5.5 $0.01188 $0.01188
Sonnet 5.5 $0.00594 $0.00594
Haiku 4.5 $0.00297 $0.00297

Measured 15d ago against content hash 4decfee034c1, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

typescript-patterns 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 15d ago.

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-patterns.mdc · 512 lines

How it starts

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

TypeScript Development Patterns

You are an expert in TypeScript, modern JavaScript, and type-safe development practices.

Core TypeScript Principles

  • Use strict TypeScript configuration
  • Prefer type inference over explicit typing when clear
  • Use union types and discriminated unions effectively
  • Implement proper type guards and validation
  • Leverage generic types for reusability
  • Use as const for immutable data structures
  • Prefer interfaces over type aliases for object shapes

Type Definitions

Interface Design

// Use interfaces for object shapes
interface User {
  readonly id: string
  name: string
  email: string
  createdAt: Date
  updatedAt: Date
}

// Use generic interfaces for reusability
interface ApiResponse<T> {
  data: T
  success: boolean
  message?: string
}

// Extend interfaces for specialization
interface AdminUser extends User {
  role: "admin" | "super_admin"
  permissions: Permission[]
}

Union Types and Discriminated Unions

// Use discriminated unions for type safety
type PaymentStatus = 
  | { status: "pending"; pendingReason: string }
  | { status: "completed"; completedAt: Date }
  | { status: "failed"; error: string }

// Type guards for discriminated unions
function isCompletedPayment(
  payment: PaymentStatus
): payment is Extract<PaymentStatus, { status: "completed" }> {
  return payment.status === "completed"
}

Generic Types

// Generic utility types
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
type RequiredFields<T, K extends keyof T> = T & Required<Pick<T, K>>

// Generic function types
type AsyncFunction<T extends any[], R> = (...args: T) => Promise<R>

// Generic class types
class Repository<T extends { id: string }> {
  async findById(id: string): Promise<T | null> {
    // Implementation
  }
  
  async create(data: Omit<T, "id">): Promise<T> {
    // Implementation
  }
}

Advanced Type Patterns

Conditional Types

// Conditional types for API responses
type ApiResult<T> = T extends string 
  ? { message: T }
  : T extends Error
  ? { error: T }
  : { data: T }

// Mapped types for form validation
type ValidationErrors<T> = {
  [K in keyof T]?: string[]
}

// Template literal types
type EventName<T extends string> = `${T}:created` | `${T}:updated` | `${T}:deleted`
type UserEvents = EventName<"user"> // "user:created" | "user:updated" | "user:deleted"

Read the full file on GitHub · 512 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. 15d ago First seen · 512 lines · 2,969 tokens per session scan A 4decfee034c1

Subscribe to this mod's changes

typescript-patterns is a cursor rule published in the GitHub repository lambda-curry/medusa2-starter (164 stars, last pushed 17d ago), licensed MIT. It adds 2,969 tokens to every session, about $0.0119 per session on Opus 5.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-11-15.

Related

typescript-patterns compared with cursor rules from other repositories

typescript-patterns next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
typescript-patternslambda-curry/medusa2-starterCursor rule16417d agoMITA2,969Cursor
vue-typescript-patternssoaring-xiongkulu/easyaiotCursor rule7673d agoMITA381Cursor
nextjs-typescript-app-cursorrules-prompt-filePatrickJS/awesome-cursorrulesCursor rule41k6mo agoCC0-1.0A66Cursor
tsun-pany/v3-admin-viteCursor rule7.1k4mo agoMITA287Cursor
typescript-securityfmflurry/settings-opencodeCursor rule17024d agoMITA0Cursor
naming-conventions-ruleholtwood/awesome-cursorrules-zhCursor rule2441mo agoMITA64Cursor
typescriptjeffgreendesign/textrawlCursor rule62d agoMITA0Cursor