How to use
- Copy the installation command and review the source package before installing it in your own agent environment.
- Check the source document for required tools, credentials and supported hosts.
- Describe your input and desired deliverable; review the output against the source material.
npx skills add https://github.com/j4flmao/agent_skills_nodejs_nestjs --skill designing-oop-typescriptBefore you start
- Installation does not include a model subscription, API allowance or permission to access your files.
- Repository stars and installation counts describe activity, not an independent quality or security test.
Rendered from the source repository. Headings, examples, code, tables, links, and referenced images are preserved.
Designing OOP TypeScript
When to use
- Creating new domain entities or value objects
- Refactoring procedural code into OOP
- Designing class hierarchies with SOLID principles
Core rules
- Classes over functions: all behavior encapsulated in classes
- Explicit access modifiers:
public,protected,privatealways written - SRP: one responsibility per class, split when growing
- Encapsulation: no public mutable fields, expose intent via methods
- Immutability: value objects are readonly, entities use private state
- SOLID: Single responsibility, Open/closed, Liskov, Interface segregation, Dependency inversion
Reference shape (TypeScript)
Domain Entity
export class User {
private constructor(
private readonly _id: string,
private _email: string,
private _isActive: boolean
) {}
static create(id: string, email: string): User {
return new User(id, email, true);
}
get id(): string { return this._id; }
get email(): string { return this._email; }
deactivate(): void {
if (!this._isActive) throw new BusinessError('ALREADY_INACTIVE', 'User already inactive');
this._isActive = false;
}
}Value Object
export class Email {
private constructor(private readonly value: string) {}
static create(email: string): Email {
if (!PATTERNS.EMAIL.test(email)) throw new ValidationError([{ field: 'email', message: 'Invalid' }]);
return new Email(email.toLowerCase());
}
equals(other: Email): boolean {
return this.value === other.value;
}
}Examples — Do
class Order {
private items: OrderItem[] = [];
addItem(item: OrderItem): void { this.items.push(item); }
get total(): number { return this.items.reduce((sum, i) => sum + i.price, 0); }
}Examples — Don't
// ❌ Function module, no encapsulation
export function createUser(id: string, email: string) { return { id, email }; }
// ❌ Public mutable fields
class User { id: string; email: string; }Checklist
- [ ] Classes with explicit access modifiers
- [ ] No public mutable fields
- [ ] Value objects are immutable
- [ ] Entities encapsulate behavior
- [ ] SOLID principles applied
See reference/oop-patterns.md for full patterns.



