📖 About TypeScript
TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. It adds optional static typing, classes, interfaces, and many other features to JavaScript, making it easier to build and maintain large-scale applications.
🎯 Best For
- Large-scale web applications
- Frontend frameworks (React, Angular, Vue)
- Node.js backend services
- Full-stack development
- API development with type safety
🔧 Key Features
- Static type checking
- Type inference and advanced types
- Interfaces and type aliases
- Generics for reusable components
- Decorators and metadata
- Excellent IDE support and IntelliSense
🛠️ Development Tools
Build
tsc
Test
jest
Coverage
jest --coverage
Run
ts-node
📄 Package Contents (7 files)
AGENTS_RULES.md
Complete AI agent rules (universal)
- TYPESCRIPT-specific best practices
- TDD workflow (Red-Green-Refactor)
- DDD principles and patterns
- Git workflow and commit format
- Code quality principles
.cursorrules
Quick reference for Cursor IDE
- Essential rules summary
- Links to full documentation
- Optimized for quick loading
.gitignore
Git exclusions
- TYPESCRIPT-specific patterns
- Build artifacts
- IDE configuration files
- Dependency directories
AGENTS.md
Quick reference guide
- Common patterns
- Best practices summary
- Quick troubleshooting
README.md
Project template with examples
- Setup instructions
- Sample code and structure
- Testing examples
- Build and run commands
CODE_QUALITY_PRINCIPLES.md
Quality principles and best practices
- Avoid default values (fail-fast)
- Consistency across code paths
- Extract reusable functions
- TYPESCRIPT-specific examples
CONTRIBUTING.md
Contribution guidelines
- TDD workflow (Red-Green-Refactor)
- Git commit format
- Code review process
- Testing requirements (90% coverage)
💻 Code Examples
Type Safety & Interfaces
interface User {
id: string;
name: string;
email: string;
}
function createUser(name: string, email: string): User {
return {
id: crypto.randomUUID(),
name,
email
};
}
const user = createUser("John", "john@example.com");
// user.age = 30; // Error: Property 'age' does not exist
Result Pattern with Discriminated Unions
type Result<T, E> =
| { success: true; value: T }
| { success: false; error: E };
function parseUser(data: unknown): Result<User, string> {
if (typeof data !== 'object' || data === null) {
return { success: false, error: 'Invalid data' };
}
const user = data as User;
if (!user.name || !user.email) {
return { success: false, error: 'Missing fields' };
}
return { success: true, value: user };
}
Generics & Type Guards
function isNotNull<T>(value: T | null): value is T {
return value !== null;
}
function findById<T extends { id: string }>(
items: T[],
id: string
): T | null {
return items.find(item => item.id === id) ?? null;
}
const users: User[] = [/* ... */];
const user = findById(users, "123");
if (isNotNull(user)) {
console.log(user.name); // Type-safe
}