Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Explains the SOLID principles for Node.js and TypeScript with functional-style code examples and violation-versus-correct comparisons.
75% 96%+21 ptsof test cases passed
Passed 23 of 24 test cases with the skill, and 18 of 24 without it.
3 of 3 safety checks passed
Not used yet
SOLID principles adapted for functional and TypeScript-first development.
A module/function should have only one reason to change.
// Bad: Does validation, processing, and notification
const processOrder = async (order: Order) => {
// Validation
if (!order.items.length) throw new Error('Empty order');
if (order.total < 0) throw new Error('Invalid total');
// Processing
const processed = { ...order, status: 'processed' };
await db.orders.save(processed);
// Notification
await emailService.send(order.userId, 'Order confirmed');
return processed;
};
// Good: Separate responsibilities
const validateOrder = (order: Order): Result<Order, ValidationError> => {
if (!order.items.length) return Result.fail(emptyOrderError());
if (order.total < 0) return Result.fail(invalidTotalError());
return Result.ok(order);
};
const saveOrder = (db: Database) =>
async (order: Order): Promise<Order> => {
const processed = { ...order, status: 'processed' };
Next to this one in the catalogue, plus popular skills in the same category.