Skip to content
Back to skills

Typescript Rules

ASecurity

TypeScript coding conventions

  • 66 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 26, 2026
developmenttypescriptgoapi

Works with

  • api

Security analysis

A100/100

Scanned May 27, 2026

npx -y skills add dlupiak/claude-session-dashboard --skill typescript-rules --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Typescript Rules?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Typescript Rules
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/dlupiak-typescript-rules/badge)](https://www.skillsdirectory.com/skills/dlupiak-typescript-rules)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: typescript-rules
description: TypeScript coding conventions
user-invocable: false
---

# TypeScript Rules

## Types
- Never use `any` — use `unknown` with type guards or explicit types
- Prefer `interface` for object shapes, `type` for unions/intersections
- Export types alongside their functions, not from barrel files
- Use `satisfies` for type-safe object literals: `const x = { ... } satisfies Config`

## Imports
- Use `@/` path alias for imports from `apps/web/src/`
- Group imports: external libs → `@/lib/` → relative slice imports
- Use `type` imports for type-only: `import type { Foo } from './types'`

## Architecture Boundaries

### Vertical slice structure (`src/features/<slice>/`)
- Each slice owns its own server functions, queries, components, and types
- No cross-slice imports — shared code goes in `src/lib/`
- `src/lib/` modules must NOT import from `src/features/`

### File naming
- Server function files: `*.server.ts`
- Query/hooks files: `*.queries.ts`
- Component files: PascalCase (e.g., `SessionCard.tsx`)
- Test files: `*.test.ts(x)` co-located with source

## Error Handling
- Throw typed errors, not strings: `throw new Error('message')`
- Use discriminated unions for result types: `{ ok: true; data: T } | { ok: false; error: string }`
- Catch `unknown`, narrow with `instanceof`

## Functions
- Prefer named function declarations over arrow functions for top-level exports
- Use explicit return types on exported functions
- Keep functions small — max ~50 lines

## Zod
- Validate all external input (API responses, form data, URL params) with Zod
- Co-locate schemas with server functions, not in separate schema files
- Use `z.infer<typeof schema>` for derived types

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…