fp-types-ref
它能做什么
帮你在 fp-ts 库中选择合适的类型(如 Option、Either、Task),用来组织你的 TypeScript 代码,尤其适用于处理可能缺失的值,或可能出错的异步操作。
适用场景
- ✓需要在 Option、Either、Task 或 TaskEither 之间做选择时。
- ✓不确定如何导入 fp-ts 类型时。
- ✓想快速查阅 fp-ts 常见模式的指南时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-types-ref/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“对于一个既是异步又可能失败的函数,我应该用哪种 fp-ts 类型?”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会根据操作是否异步、是否可能失败,以及值是否可能不存在,用一张简单的流程图帮你做选择。它还会提供导入方式和常见模式的代码示例。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
fp-ts Quick Reference
When to Use
- You need help choosing between
Option,Either,Task,TaskEither, or related fp-ts types. - The task is about imports, decision guidance, or selecting the right abstraction for a TypeScript flow.
- You want a compact reference for common fp-ts type choices and patterns.
Which Type Should I Use?
Is the operation async?
├─ NO: Does it involve errors?
│ ├─ YES → Either<Error, Value>
│ └─ NO: Might value be missing?
│ ├─ YES → Option<Value>
│ └─ NO → Just use the value
└─ YES: Does it involve errors?
├─ YES → TaskEither<Error, Value>
└─ NO: Might value be missing?
├─ YES → TaskOption<Value>
└─ NO → Task<Value>
Common Imports
// Core
import { pipe, flow } from 'fp-ts/function'
// Types
import * as O from 'fp-ts/Option' // Maybe exists
import * as E from 'fp-ts/Either' // Success or failure
import * as TE from 'fp-ts/TaskEither' // Async + failure
import * as T from 'fp-ts/Task' // Lazy async; no typed error channel
import * as A from 'fp-ts/Array' // Array utilities
One-Line Patterns
| Need | Code |
|---|---|
| Wrap nullable | O.fromNullable(value) |
| Default value | O.getOrElse(() => fallbackValue) |
| Transform if exists | O.map(fn) |
| Chain optionals | O.flatMap(fn) |
| Wrap try/catch | E.tryCatch(() => risky(), toError) |
| Wrap async | TE.tryCatch(() => fetch(url), toError) |
| Run pipe | pipe(value, fn1, fn2, fn3) |
Pattern Match
// Option
pipe(maybe, O.match(
() => 'nothing',
(val) => `got ${val}`
))
// Either
pipe(result, E.match(
(err) => `error: ${err}`,
(val) => `success: ${val}`
))
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Reference scope
These are fp-ts 2.x fragments. Supply application variables, types, validators and imports, and check the installed version. map does not catch thrown exceptions. Task has no typed error channel; an improperly wrapped promise can still reject. Use tryCatch at fallible boundaries.
Official API: fp-ts modules.
常见问题
Option、Either 和 Task 是什么?
它们是一些帮助你更安全、更有条理地处理常见编程场景的类型,比如值可能不存在(Option)、操作可能成功也可能失败(Either),以及操作需要一段时间才能完成(Task)。
“异步”是什么意思?
指一个操作不会立即完成,而是在将来某个时刻才完成。例如从服务器获取数据,或读取文件。
fp-ts 是什么?
它是一个流行的 TypeScript 库,把函数式编程概念带进来,帮助你写出更健壮、更可预测的代码。
详情
作者的原始描述
Quick reference for fp-ts types. Use when user asks which type to use, needs Option/Either/Task decision help, or wants fp-ts imports.
热度
- GitHub 星标
- 48k
- 排名
- #4652
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。