typescript

A set of coding rules for TypeScript, a version of JavaScript that adds types and other checks. It covers naming, file extensions, type inference, imports, and running TypeScript with Node.

In plain words
What is it for?
Use it when writing or reviewing TypeScript and TSX files, especially code that runs in Node or uses JavaScript modules.
Why use it?
It helps keep TypeScript code consistent and avoids unnecessary annotations, unsafe type casts, and outdated ways of running files.

Cursor rule

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/transloadit/node-sdk/typescript
Clone the repo
git clone --depth 1 https://github.com/transloadit/node-sdk
Per session 1,267 This file is loaded in full into every session.
When invoked 1,267 The same file — it is already loaded in full.
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.01267 $0.01267
Opus 5 $0.00633 $0.00633
Sonnet 5 $0.00253 $0.00253
Haiku 4.5 $0.00127 $0.00127

Measured yesterday against content hash 23387551d699, 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.

.ai/rules/typescript.mdc · 79 lines

How it starts

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

For Typescript:

  • Favor contentGapItemSchema = z.object() over ContentGapItemSchema = z.object()
  • Favor from './PosterboyCommand.ts' over from './PosterboyCommand'
  • Favor return ideas.filter(isPresent) over ideas.filter((idea): idea is Idea => idea !== null)
  • Favor using .tsx over .jsx file extensions.
  • Use Node v24's native typestripping vs tsx or ts-node. These days you do not even need to pass --experimental-strip-types, node app.ts will just work.
  • In ESM TypeScript, use import.meta.dirname / import.meta.filename or URL objects instead of rebuilding __dirname with fileURLToPath(import.meta.url) unless compatibility requires it.
  • Use satisfies when you need literal preservation or structural conformance while keeping the expression's inferred type. If the variable should simply have a declared type, use a type annotation instead.
  • Avoid redundant type annotations inside expressions when TypeScript already infers the exact type, especially callback parameters. Keep explicit return types and public boundary annotations.
  • Avoid as, consider it a sin. If a cast is unavoidable, keep it as narrow as possible and explain the upstream type mismatch or runtime invariant.
  • For DOM queries and browser APIs, prefer runtime narrowing such as element instanceof HTMLAnchorElement over type casts. Decide explicitly whether a missing element should throw, return early, or no-op.
  • Browser/client code must not use Node-only globals or APIs such as Buffer. Use browser platform APIs such as btoa, TextEncoder, Blob, or URL, or isolate the logic in server-only code.
  • When browser APIs are missing TypeScript declarations, augment the global interface in _types/global.ts (or the relevant shared global types file) and narrow with checks such as typeof navigator.setAppBadge === 'function' instead of casting navigator locally.
  • Prefer typed DOM properties such as element.inert = true and element.tabIndex = -1 when the platform exposes them. Use setAttribute() only when you intentionally need raw attribute semantics.
  • Favor unknown over any, consider any a sin
  • Avoid as unknown as ... and biome-ignore lint/suspicious/noExplicitAny. If an upstream library type forces either, isolate it in a tiny adapter/helper with a comment naming the bad upstream type.
  • Every @ts-expect-error must be narrow and include a short explanation of the upstream type gap or invariant that makes it safe.
  • Favor validating data with Zod over using any or custom type guards
  • Extract duplicated Zod object shapes, regexes, and descriptions into reusable schema fragments when they describe the same domain concept. Keep property-level concerns such as .optional() and .default() at the property site unless absence is intrinsic to the reusable fragment.
  • Boolean Zod properties should usually use explicit defaults instead of .optional() when omission has normal default behavior. Only leave a boolean optional when undefined is semantically different from false.
  • Prefer z.union([...]) over chained .or() for multi-branch unions, and prefer z.enum() or literal unions over clever regexes when the accepted values are finite and autocomplete matters.
  • Do not duplicate supported values in user-facing schema descriptions when schema metadata such as enums or suggested values can carry that information.
  • In TypeScript files, use TypeScript syntax instead of JSDoc type annotations. In JavaScript files, prefer JSDoc @import / @param forms over noisy inline import('...') annotations, and make sure @type annotates the expression it is meant to type.
  • Avoid hand-written .d.ts files when the declaration can come from TypeScript source or generation. If a declaration file is unavoidable, do not rely on skipLibCheck to hide duplicate or invalid exports.
  • Avoid Reflect.get for normal object property reads. After narrowing to a record, use record[key] or a small typed reader helper. Only keep Reflect.get for exotic receivers such as proxies or framework objects where its semantics are intentionally required, and document why.
  • Prefer Number.isFinite() / Number.isNaN() over global isFinite() / isNaN() so numeric checks do not silently coerce non-numbers.
  • isRecord style guards must reject arrays: typeof value === 'object' && value !== null && !Array.isArray(value). Prefer importing a shared guard when one already exists in the relevant shared layer.
  • Type-only refactors must preserve runtime behavior. If the behavior intentionally changes, call it out in the PR and cover the changed behavior with tests.
  • Use ECMAScript #private fields for private state. Do not rely on underscore names or TypeScript private to imply runtime privacy.
  • Prefer Zod defaults/preprocessing for schema-backed default values instead of duplicating default objects in runtime code.
  • For local TypeScript files, import with the .ts / .tsx extension (not .js, not extensionless). Note: we do not currently enable the TS 5.7 rewriteRelativeImportExtensions compiler option, because it errors on non-relative imports that include .ts/.tsx (for example via paths aliases like @/…). If/when we enable it, we will need to adjust those imports first.
  • Favor defining props as an interface over inline
  • Favor explicit return types over inferring them as it makes typescript a lot faster in the editor on our scale

Read the full file on GitHub · 79 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 · 79 lines · 1,267 tokens per session scan A 23387551d699

Subscribe to this mod's changes

typescript is a cursor rule published in the GitHub repository transloadit/node-sdk (73 stars, last pushed 2d ago), licensed MIT. It adds 1,267 tokens to every session, about $0.0063 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-30.