Effect TypeScript 惯用法
effect-ts-idioms
编写地道的现代 Effect TypeScript 代码,使用 Effect.gen 或清晰的 pipeline(管道)、类型化错误通道、Context 与 Layer 服务,以及资源安全的运行时边界。在使用 Effect、@effect/platform、Schema、Layers 构建或审查代码,或开发基于 Effect 的应用程序时使用。
- License 许可
- MIT
- 最近更新
- 2026-11-11
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- effect-ts-idioms
- description
- Write idiomatic modern Effect TypeScript using Effect.gen or clear pipelines, typed error channels, Context and Layer services, and resource-safe runtime boundaries. Use when building or reviewing code with Effect, @effect/platform, Schema, Layers, or Effect-based applications.
- compatibility
- opencode
03 SKILL.md 正文
Use this skill to keep Effect code modern, explicit, and faithful to the library's model instead of falling back to Promise-first habits.
Mindset
Effect code should make three things obvious from the type and structure:
- success value
- expected failure mode
- required services/environment
Prefer Effect-native modeling over wrapping Promise code and keeping the old design.
Default style
- Use
Effect.genfor multi-step workflows, branching, and orchestration. - Use
pipe(...)plus combinators for short local transformations. - Keep effects lazy; describe work first, run it only at the program edge.
- Write explicit lambdas instead of point-free or tacit style.
Prefer:
Effect.map((user) => formatUser(user))
Over:
Effect.map(formatUser)
This follows the official guidance to avoid tacit usage because it can hurt inference, overload resolution, and stack traces.
Error modeling
- Put expected domain and operational failures in the error channel.
- Reserve defects for truly unexpected bugs or violated invariants.
- Prefer tagged, structured errors over raw strings.
- Recover close to the boundary where a fallback is meaningful.
Good defaults:
Effect.fail(...)for expected failuresEffect.try(...)/Effect.tryPromise(...)when wrapping throwing or rejecting APIscatchTag,catchAll, andmapErrorfor recovery and translation
Avoid:
- throwing inside
Effect.sync - burying business failures in
Option.none()when the caller needs an explanation - converting everything to
unknownorErrortoo early
Services, Context, and Layers
- Model shared capabilities as services with
Context.Tag. - Provide implementations with
Layerfor reusable dependency graphs. - Keep service interfaces small and capability-oriented.
- Inject services through requirements, not global singletons.
Prefer:
- pure domain functions for pure logic
- service tags for effectful capabilities
- layers at app assembly boundaries
Do not manually thread giant dependency objects through business logic if Effect requirements can model them cleanly.
Resource safety
- Use scoped resource management for files, sockets, clients, subscriptions, locks, and anything requiring cleanup.
- Prefer
Effect.acquireRelease,Effect.addFinalizer, and scoped layers over manual cleanup bookkeeping. - Treat interruption as a normal part of execution, not an edge case.
If something must always be cleaned up, model it in the effect structure rather than relying on convention.
Runtime boundaries
- Run effects at the outermost program boundary.
- In Node apps, prefer
NodeRuntime.runMain(...)for the main program so shutdown is graceful. - Avoid
Effect.runPromiseorEffect.runSyncinside library code, helpers, or domain modules. - Convert external APIs at the edge, then stay inside Effect.
Concurrency and composition
- Use fibers and combinators deliberately; choose sequential vs concurrent behavior explicitly.
- Prefer
Effect.all(...)and concurrency options for independent work. - Use retries, schedules, timeouts, and supervision as first-class tools instead of ad hoc loops.
- Keep concurrent workflows readable; name intermediate effects when needed.
Data modeling
- Prefer
Schemaat boundaries for parsing, validation, and encoding. - Prefer
Option,Either,Data,Chunk,Duration, and other Effect data types when they make semantics clearer. - Avoid
nullandundefinedin domain modeling whenOptionor a tagged union is better.
Interop rules
- Wrap promise-returning APIs with
Effect.tryPromiseunless rejection is impossible. - Wrap callback or event APIs once, then expose an Effect-native interface.
- Keep framework glue thin.
Review checklist
When writing or reviewing Effect code, check:
- Is expected failure in the error channel?
- Are services expressed as requirements instead of hidden globals?
- Is resource cleanup guaranteed by structure?
- Is the runtime only used at the edge?
- Is the code using
Effect.genor pipelines in a way that is easy to follow? - Is this still really Effect code, or just Promise code wrapped at the last second?
04 同仓库更多 Skills
技能创建与优化评估
skill-creator
创建新技能、修改并改进现有技能,以及衡量技能性能。当用户想要从头创建技能、编辑或优化现有技能、运行评估(eval)来测试技能、通过方差分析对技能性能做基准测试,或优化技能描述以提高触发准确率时使用。
Astro v6 应用开发
modern-astro-v6
使用服务端优先渲染、islands、content collections(内容集合)、actions 以及当前 v6 安全兼容的 API,构建地道的 Astro v6 应用。在创建、审查或迁移 Astro 项目、页面、组件、内容层或集成时使用该技能。
前端界面设计与实现
frontend-design
创建富有特色、达到生产级且设计精良的前端界面。当用户要求构建 Web 组件、页面、工件、海报或应用时使用此技能(例如网站、落地页、仪表板、React 组件、HTML/CSS 布局,或为任意 Web UI 提供样式美化)。生成富有创意、精致的代码和 UI 设计,避免千篇一律的 AI 风格。
Elixir 与 Phoenix 惯用法
elixir-idioms
编写地道的 Elixir 和 Phoenix 代码,运用模式匹配、可组合的小型函数、OTP 友好的边界设计以及 BEAM 感知的错误处理。在创建或审查 Elixir 代码、API、GenServer、Phoenix 应用、Ecto 代码或测试时使用。
Ash 框架惯用法
ash-framework-idioms
编写地道的 Ash 框架代码,使用意图明确的 action(动作)、代码接口、关系管理、DSL 优先的建模,以及框架原生的 change/preparation(变更/准备),而非临时的辅助层。在创建或审查 Ash resource(资源)、domain(域)、action(动作)、query(查询)或 Phoenix 集成时使用。