Install any skill in seconds. Free to start, no credit card required.
Get Started Free →zrosenbauer/ts-best-practices-functional
This skill should be used when the user wants to refactor TypeScript code to functional patterns or write new code following functional doctrine. Common triggers include "make this functional", "remove the class", "use Result instead of throw", "stop mutating this", and "refactor to factory function". Bakes in factory functions over classes, Result<T,E> over exceptions, immutable state via spread/map/filter, and pure functions composed in pipelines. Skip when the user wants general TS hygiene (u
Passed 23 of 23 test cases with the skill, and 20 of 23 without it.
and 1 more in the full report
3 fixed20 passed either way0 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 3 test cases the skill fixed. Same model, same prompt, with and without the skill.
Here is a TypeScript configuration loader function that parses raw JSON strings and validates required fields, throwing generic exceptions whenever parsing or validation fails. Can you rewrite this module to align with functional TypeScript principles so that failure modes are represented directly in the return type signatures rather than thrown at runtime?
| Checked | Without skill | With skill |
|---|---|---|
| Uses a Result type with an ok boolean discriminator property | Missed | Passed |
| Returns an ok branch with the parsed config on success | Passed | Passed |
| Returns an err branch with structured error information on failure | Passed | Passed |
The instructions your model reads when the skill loads.
Refactor or author TypeScript using a functional doctrine: factories over classes, Result<T,E> over exceptions, immutable state via spread/map/filter, and pure functions composed in pipelines.
| Prefer | Over | Why |
|---|---|---|
| Data transformations | Mutations | Predictable, easier to reason about |
| Functions | Methods | No this binding issues |
| Composition | Inheritance | Mix behaviors without coupling |
| Explicit | Implicit | State passed in, not hidden |
| Factories | Classes | Closure-encapsulated state, no new |
Use a factory function returning an interface to encapsulate state. Closures make the state truly private; no this to bind.
function createCounter(initial: number = 0): Counter { let value = initial return { increment: () => ++value, decrement: () => --value, getValue: () => value, } }
const counter = createCounter(10) counter.increment() // 11
test cases passed, vs 20 / 23 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.