javascript-typescript
JavaScript & TypeScript
Best practices for JavaScript and TypeScript development.
When to Use
- Writing frontend or backend JavaScript/TypeScript code
- Setting up new Node.js or browser projects
- Code review and refactoring
TypeScript Guidelines
Strict Mode
Always enable strict mode in tsconfig.json:
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true
}
}
Type Best Practices
// Prefer interfaces for object shapes
interface User {
id: string;
name: string;
email: string;
}
// Use union types for alternatives
type Status = 'idle' | 'loading' | 'success' | 'error';
// Prefer readonly for immutable data
class Config {
readonly apiUrl: string;
}
JavaScript Patterns
Async/Await
// Prefer async/await over promise chains
async function fetchData(url) {
const response = await fetch(url);
return response.json();
}
Error Handling
try {
await operation();
} catch (error) {
logger.error('Operation failed', { error });
throw error; // Re-throw or handle
}
Resources
More from kinhluan/skills
scheduling-algorithms
Job scheduling algorithms for parallel and distributed systems
5ddd-core
Professional Strategic Domain-Driven Design (DDD) Hub. Use this skill for Event Storming, identifying Subdomains, defining Bounded Contexts, and mapping Domain Models to the heart of your architecture.
4c4-model
Professional C4 model architecture hub for "Design-to-Code Sync". Use this skill to navigate the C4 hierarchy, map diagrams to stakeholders, avoid architectural anti-patterns, and choose the right level for designing or documenting existing codebases.
4ddd-tactical
Tactical Domain-Driven Design (DDD) with Scoring Rubric. Use this skill when designing internal domain models or performing architectural reviews to ensure domain logic is isolated and rich.
4ddd-patterns
Advanced Domain-Driven Design (DDD) Integration Patterns. Use this skill for implementing CQRS, Event Sourcing, the Outbox Pattern, and Anti-Corruption Layers (ACL) in distributed systems.
4c4-level4-code
Specialized in Code diagrams (Level 4) of the C4 model. Use this skill when the user needs to describe the internal implementation of a component using UML class diagrams or database ER diagrams.
4