typescript
TypeScript static typing with interfaces, generics, decorators, and type inference. Use for .ts files.
Best use case
typescript is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
TypeScript static typing with interfaces, generics, decorators, and type inference. Use for .ts files.
Teams using typescript should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/typescript/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How typescript Compares
| Feature / Agent | typescript | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
TypeScript static typing with interfaces, generics, decorators, and type inference. Use for .ts files.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# TypeScript
Static typing for JavaScript with advanced type features for safer, more maintainable code.
## When to Use
- Working with `.ts` or `.tsx` files
- Building type-safe APIs and applications
- Defining complex data models with validation
- Creating reusable generic utilities
## Quick Start
```typescript
// Define a typed interface
interface User {
id: string;
name: string;
email: string;
createdAt: Date;
}
// Type-safe function
async function fetchUser(id: string): Promise<User | undefined> {
const response = await fetch(`/api/users/${id}`);
return response.ok ? response.json() : undefined;
}
```
## Core Concepts
### Interfaces and Types
```typescript
// Interface for object shapes (extendable)
interface User {
id: string;
name: string;
email: string;
}
// Type for unions, intersections, mapped types
type Status = "pending" | "active" | "inactive";
type UserWithStatus = User & { status: Status };
```
### Generics
```typescript
// Generic functions
function first<T>(items: T[]): T | undefined {
return items[0];
}
// Generic constraints
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}
// Generic interfaces
interface Repository<T extends { id: string }> {
findById(id: string): Promise<T | null>;
save(entity: T): Promise<T>;
delete(id: string): Promise<void>;
}
```
## Common Patterns
### Type Guards
**Problem**: Narrowing unknown types at runtime.
**Solution**:
```typescript
// Type predicates
function isUser(value: unknown): value is User {
return (
typeof value === "object" &&
value !== null &&
"id" in value &&
"name" in value
);
}
// Discriminated unions
type Result<T> = { success: true; data: T } | { success: false; error: string };
function handleResult<T>(result: Result<T>) {
if (result.success) {
console.log(result.data); // Type: T
} else {
console.error(result.error); // Type: string
}
}
```
### Utility Types
```typescript
// Make all properties optional
type Partial<T> = { [P in keyof T]?: T[P] };
// Pick specific properties
type UserPreview = Pick<User, "id" | "name">;
// Omit specific properties
type UserCreate = Omit<User, "id" | "createdAt">;
// Brand types for nominal typing
type UserId = string & { readonly brand: unique symbol };
```
## Best Practices
**Do**:
- Enable `strict` mode in `tsconfig.json`
- Use `unknown` instead of `any` for truly unknown types
- Use discriminated unions for state management
- Export types alongside implementations
**Don't**:
- Use `any` to bypass type checking
- Use type assertions (`as`) when narrowing works
- Ignore TypeScript errors with `// @ts-ignore`
- Mix `interface` and `type` inconsistently
## Troubleshooting
| Error | Cause | Solution |
| ---------------------------------------- | ------------------------- | ---------------------------------- |
| `Type 'X' is not assignable to type 'Y'` | Type mismatch | Check types, use type guards |
| `Object is possibly undefined` | Nullable value access | Use optional chaining or narrowing |
| `Cannot find module` | Missing type declarations | Install `@types/package` |
## References
- [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/)
- [TypeScript Deep Dive](https://basarat.gitbook.io/typescript/)Related Skills
template
Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].
zsh
Zsh shell with oh-my-zsh. Use for terminal shell.
zed
Zed high-performance collaborative editor. Use for fast editing.
xcode
Xcode Apple development IDE with simulators. Use for iOS/macOS development.
webstorm
WebStorm JavaScript IDE with debugging. Use for web development.
webpack
Webpack module bundler with loaders and plugins. Use for bundling.
warp
Warp modern terminal with AI. Use for terminal work.
vscode
Visual Studio Code editor with extensions and debugging. Use for code editing.
vite
Vite fast build tool with HMR. Use for modern frontend builds.
visual-studio
Visual Studio IDE for Windows with debugging and profiling. Use for .NET development.
vim
Vim text editor with motions, macros, and plugins. Use for terminal editing.
turbopack
Turbopack Rust-powered bundler. Use for fast builds.