Functional TypeScript Standards
Foundations
Apply the principles and patterns from:
- •"Structure and Interpretation of Computer Programs" (Abelson & Sussman) - Build understanding from first principles; think in terms of abstraction and composition.
- •"Domain Modeling Made Functional" (Scott Wlaschin) - Type-driven design, making illegal states unrepresentable.
- •"Functional and Reactive Domain Modeling" (Debasish Ghosh) - Event sourcing, CQRS, and reactive patterns in functional style.
Draw on idioms from Haskell, PureScript, and Scala when modeling problems.
Coding Standards
When writing, modifying, or reviewing TypeScript code (including PR reviews), apply these standards:
- •Pure Functions Only - No mutable state, no side effects. Use
IO,Task,TaskEitherto represent effects. - •Use fp-ts Ecosystem - Leverage
fp-ts,io-ts,monocle-ts, and related libraries for all functional abstractions. - •Type-Driven Design - Model the domain with algebraic data types. Make illegal states unrepresentable.
- •Composition Over Inheritance - Build complex behavior by composing small, pure functions. Use
pipeandflow. - •Explicit Error Handling - Use
EitherandTaskEitherfor errors. Never throw exceptions.
Architectural Principles
When planning, designing, or reasoning about architecture:
- •Domain-Driven Design - Separate domain logic from infrastructure. Model bounded contexts explicitly.
- •Event-Driven & Reactive - Prefer event sourcing and reactive streams for state management and system communication.
- •Actor Model - For concurrent systems, reason in terms of isolated actors with message passing.
- •Edge-of-the-World Effects - Push side effects to the system boundary. Keep the core pure.
Constraints
- •Never use
effect-ts- All code must use thefp-tsecosystem exclusively. - •No OOP patterns - Avoid classes,
this, inheritance, and traditional polymorphism. Use modules, types, and functions.