Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Summarizes common code design patterns with TypeScript examples, including creational ones like Factory and Builder, as a quick reference.
82% 91%+9 ptsof test cases passed
Passed 20 of 22 test cases with the skill, and 18 of 22 without it.
3 of 3 safety checks passed
Not used yet
Quick reference for common patterns. Use these as starting points, not rigid templates.
// When: Creating objects without specifying exact class
interface Product { use(): void }
class ConcreteProductA implements Product {
use() { console.log('Using A') }
}
class ProductFactory {
static create(type: string): Product {
const products = { a: ConcreteProductA };
return new products[type]();
}
}
// When: Complex object construction with many optional params
class QueryBuilder {
private query = { select: '*', from: '', where: [] };
select(fields: string) { this.query.select = fields; return this; }
from(table: string) { this.query.from = table; return this; }
where(condition: string) { this.query.where.push(condition); return this; }
build() { return this.query; }
}
// Usage
const query = new QueryBuilder()
.select('name, email')
.from('users')
.where('active = true')
Next to this one in the catalogue, plus more from the same author.