Typescript Best Practices
ASecurityPrefer composition and constructor injection when the base class is becoming large. Split each capability behind a small interface and make collaborators explicit: ```ts export interface UserRepository { findById(id: string): Promise<User | null>; } export interface AuditLogger { record(event: string): Promise<void>; } export interface User { readonly id: string; } export class UserService { public constructor( private readonly repository: UserRepository, private readonly auditLogger: AuditLo...
- 584 stars
- 0 votes
- 0 copies
- 3 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 11 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill typescript-best-practices --agent claude-codeAre you the author of Typescript Best Practices?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-typescript-best-practices-cdb23929)Prefer composition and constructor injection when the base class is becoming large. Split each capability behind a small interface and make collaborators explicit:
```ts
export interface UserRepository {
findById(id: string): Promise<User | null>;
}
export interface AuditLogger {
record(event: string): Promise<void>;
}
export interface User {
readonly id: string;
}
export class UserService {
public constructor(
private readonly repository: UserRepository,
private readonly auditLogger: AuditLogger,
) {}
public async load(id: string): Promise<User | null> {
const user = await this.repository.findById(id);
if (user) {
await this.auditLogger.record(`user.loaded:${user.id}`);
}
return user;
}
}
```
Move cohesive behavior into focused services or strategy objects and compose them in the caller. This keeps classes small and testable without a singleton or a deeper inheritance hierarchy; use `private`/`protected`/`public` deliberately and retain explicit return types.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.