Iván

TypeScript

開發程式設計v1.0.5
作者:Iván更新於 2026-07-25共 6 個版本 · 最新版本釋出於 2026-07-25typescript@clawhub_ivangdavila/typescript
程式碼生成#Typescript

據 AlphaMoat 統計,截至 2026-10,TypeScript 累計下載 9,341 次、獲 7 個星標,按累計下載量在本次參與排名的 10,914 個 AI 技能中排名第 2,949 位,在「開發程式設計」分類(1,069 個)中排名第 229 位。

列表預設按累計下載量排序,也可按星標排序;詳情頁排名按累計下載量計算。

累計下載
9341
星標
7
全站下載量排名
#2,949
全站前 28% · 「開發程式設計」前 22%
平台累計下載星標評論
ClawHub ↗75876-
SkillHub ↗93417—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

涵蓋泛型、聯合型別、宣告檔案、模組互操作、JavaScript遷移與編譯效能。強調外部資料的執行時驗證、收窄和型別斷言依據;建議需按專案執行時、構建方式及TypeScript版本選擇。

資料釋出於 2026-10-27

可以用來做什麼

  • 審查型別安全與構建問題

什麼時候用

  • TypeScript出現型別錯誤或模組執行異常時

示例提示詞

以下是根據技能文件生成的示例,不代表實際執行結果。

檢查這段程式碼的邊界驗證和型別收窄,結合當前配置提出最小修改。

月度資料趨勢

累計下載9341
3262652797912026-03 · 累計下載 37122026-05 · 累計下載 49762026-06 · 累計下載 52842026-07 · 累計下載 60882026-08 · 累計下載 69022026-09 · 累計下載 72752026-10 · 累計下載 934126-0326-0926-10
星標7
6772026-03 · 星標 62026-05 · 星標 62026-06 · 星標 62026-07 · 星標 72026-08 · 星標 72026-09 · 星標 72026-10 · 星標 726-0326-0926-10

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。

月份累計下載環比星標
2026-109341—7
2026-097275—7
2026-086902+13.4%7
2026-076088+15.2%7
2026-065284+6.2%6
2026-054976—6
2026-033712—6

SKILL.md 原文

以下是作者釋出的原始檔案,按純文字顯示,本站未做修改或稽核;其中的連結不可點選,命令請核實後再執行。抓取於 2026-10-23。

15 KB · ClawHub v1.0.5
---
name: typescript
slug: typescript
version: 1.0.5
description: >-
  Writes, reviews, and debugs type-safe TypeScript: type errors, narrowing, generics, tsconfig
  strictness, and declaration files. Use when a build hits type errors ("not assignable",
  "possibly undefined", "excessively deep", "cannot find module"), when eliminating any or
  unchecked as casts, designing generics or discriminated unions, writing .d.ts files or typing
  untyped npm packages, configuring tsconfig or module resolution, fixing ESM/CJS import
展開全部(共 200 行)
  crashes ("ERR_REQUIRE_ESM", "x is not a function"), validating API or JSON data at runtime,
  migrating JavaScript to TypeScript or upgrading the TypeScript version, or when tsc or the
  editor gets slow or runs out of memory.
homepage: https://clawic.com/skills/typescript
changelog: "Full coverage pass: deeper guides, situation-named files, and per-user configuration"
metadata:
  clawdbot:
    emoji: 🔷
    displayName: TypeScript
    configPaths:
    - ~/Clawic/data/typescript/
---

User preferences and memory live in `~/Clawic/data/typescript/` (see `setup.md` on first use, `memory-template.md` for the file format). If you have data at an old location (`~/typescript/` or `~/clawic/typescript/`), move it to `~/Clawic/data/typescript/`.

## When To Use

- Decoding type errors: "not assignable" walls, narrowing failures, inference surprises, errors that appear only in CI
- Designing types for an API surface: generics, discriminated unions, utility types, branded types
- tsconfig decisions: strict flags, module resolution, target/lib, monorepo project references, JS-to-TS migration order
- Writing or fixing declaration files (`.d.ts`, module augmentation, publishing types)
- Code that compiles green but fails at runtime — ESM/CJS interop crashes, unvalidated external data — or tsc/editor slowness
- Not for runtime JavaScript semantics (closures, event loop, coercion) — that is the javascript skill

## Quick Reference

| Situation | Play |
|---|---|
| Value of unknown shape (API, `JSON.parse`, `catch`) | `unknown` + narrow before use; never `any` |
| Config/lookup object losing literal types | `satisfies` (TS >=4.9), not a type annotation |
| Union variant not narrowing | Add a literal discriminant field + exhaustive `never` check |
| 40-line "not assignable" error | Read the deepest `Types of property ... are incompatible` line first — root cause is at the bottom; full decoder → `errors.md` |
| Cryptic diagnostic (TS2589, TS2742, "no overload matches"), error only in CI | `errors.md` |
| Generic won't infer / variance confusion / overload design | `generics.md` |
| `Partial`/`Omit`/`Record` behaving oddly | `utility-types.md` |
| Untyped npm package, globals, augmentation, publishing types | `declarations.md` |
| JS conversion, strict-flag rollout, `as` debt, TS version upgrade | `migration.md` |
| target/module/paths choices, monorepo, project references | `tsconfig.md` |
| Green compile, runtime crash (`x is not a function`, `ERR_REQUIRE_ESM`) | `modules.md` |
| External data crossing a trust boundary | Validate at runtime at the boundary; static types only downstream → `boundaries.md` |
| tsc slow, editor lag, compiler out of memory | `performance.md` |
| Anything else typed | Default: full `strict`, infer locals, annotate exports |

Depth on demand: `errors.md` diagnostic decoding · `generics.md` inference, variance, conditional types, overloads · `utility-types.md` built-in type traps · `declarations.md` .d.ts, augmentation, publishing · `migration.md` JS-to-TS, strictness ratchets, TS upgrades · `tsconfig.md` compiler configuration · `modules.md` ESM/CJS interop · `boundaries.md` runtime validation · `performance.md` compile and editor speed.

## Core Rules

1. **Full `strict` or you are reviewing half the code.** Every flag off is a bug class the checker won't report. Greenfield: `strict: true` day one plus `noUncheckedIndexedAccess` (TS >=4.1). Legacy: stage flags with a ratchet (`migration.md`).
2. **`unknown` in, typed out.** Data you didn't construct (network, JSON, env, storage) enters as `unknown` and gets validated once at the boundary (`boundaries.md`); past that point no `any` and no re-checking.
3. **Annotate exports, infer locals.** Annotated parameters and return on every exported function put errors at the boundary that caused them, not at 30 call sites downstream; inference inside bodies keeps the noise down.
4. **Make illegal states unrepresentable.** n independent optional fields admit 2^n combinations: `{ data?: T; error?: E }` is 4 states of which 2 are illegal. A discriminated union with one variant per legal state encodes exactly the truth.
5. **Every `as` carries a proof.** A cast overrides the checker — attach the runtime guard that makes it true, or a one-line comment saying why it cannot be wrong. An unexplained cast is a deferred bug report.
6. **Exhaustive by construction.** Every `switch` over a union ends in `default: x satisfies never` (TS >=4.9) — adding a variant then becomes a compile error at every site that must handle it, which is the entire point of the union.
7. **Errors read bottom-up.** The first lines of a long diagnostic are wrappers; the root cause is the deepest `Types of property ... are incompatible` line (`errors.md`).

## Stop Using `any`

- `any` is viral both directions: it silences errors on reads AND poisons everything it's assigned to. `unknown` only blocks reads until you narrow — same flexibility, none of the spread
- `catch (e)` is `unknown` under strict since TS 4.4 (`useUnknownInCatchVariables`) — check `e instanceof Error` before `.message`
- Every remaining cast (`as`) gets either a runtime guard above it or a one-line comment saying why it's safe (rule 5)
- Ratchet, don't boil the ocean: count `any`s (typescript-eslint `no-explicit-any` + `no-unsafe-*`), record the baseline, fail CI when the count rises

## Inference & Widening

Widening:

- `let x = "hello"` is `string`; `const x = "hello"` is `"hello"` — mutability drives widening
- Object and array literals widen their members even under `const`: `const cfg = { mode: "dark" }` has `mode: string` — `as const` freezes the whole tree (readonly + literals)
- Literal arguments: primitives infer as literals, objects/arrays widen — `<const T>` type parameters (TS >=5.0) preserve them at the call site
- Function return types widen too — annotate the return when a caller needs the literal

Inference limits:

- Inference flows from arguments to parameters, not through intermediate generics — when a nested generic fails, name the intermediate type and split into two steps
- No partial type argument inference: `fn<T, U>` with one explicit argument turns off inference for the rest — use the curried two-call pattern `make<T>()(config)` to fix one and infer the other
- `NoInfer<T>` (TS >=5.4) excludes a position from inference: `declare function set<T>(vals: T[], initial: NoInfer<T>): void` — without it, a wrong `initial` widens `T` instead of erroring
- Callback parameters get contextual types only when the expected signature is known — assigning the function to a typed variable or parameter is what enables `(x) =>` without annotation

## Discriminated Unions & Narrowing

Modeling with unions:

- Add a literal `kind` field to each variant — narrowing and exhaustive switches come free (rules 4 and 6)
- Discriminant must be a literal type — a field typed `string` discriminates nothing; `as const` the source values

Narrowing failures:

- `filter(Boolean)` doesn't narrow in any TS version — write `.filter((x): x is T => Boolean(x))`. TS >=5.5 infers predicates from simple lambdas, so `.filter(x => x != null)` narrows there; below 5.5 it doesn't
- Narrowing dies inside callbacks: after `if (x)`, `arr.map(() => x.foo)` re-errors because TS assumes `x` may be reassigned — copy to a `const` before the callback
- `typeof x === "object"` includes `null` — check `x !== null` in the same condition
- `Object.keys(obj)` returns `string[]`, not `keyof typeof obj` — intentional: structural types can carry extra keys. Cast only when you own the object literal
- `Array.isArray()` on `unknown` narrows to `any[]` — element type needs its own check
- `in` narrows unions only when the property appears in exactly one branch; on unlisted properties it narrows since TS 4.9
- Destructured discriminants (`const { kind } = action; if (kind === ...)`) narrow only in TS >=4.6 — on older versions switch on `action.kind` directly

## `satisfies` vs Annotation vs Cast

Three tools, three guarantees — pick by what you need to keep:

- `const x: T = v` — checks AND widens to `T`: literal info gone, excess properties rejected
- `const x = v satisfies T` (TS >=4.9) — checks compatibility, keeps the inferred narrow type: the default for config/route/theme objects
- `v as T` — checks nothing beyond rough overlap; `"hello" as number` fails but `{} as User` compiles. It's an assertion, not a conversion

## Strict Null Handling

- `??` vs `||`: `port || 3000` turns a legitimate `0` into 3000; `port ?? 3000` only replaces `null`/`undefined`. Same for `""` in string options
- Optional chaining `?.` produces `undefined`, never `null` — APIs contracted to `null` need an explicit `?? null`
- Non-null `!` is a cast in disguise — prefer early return or narrowing; each `!` is a runtime crash candidate the compiler can no longer see

## Strictness Beyond `strict`

`strict: true` is not the strictest configuration. Flags it does NOT include:

- `noUncheckedIndexedAccess` (TS >=4.1) — `arr[i]` and `record[key]` become `T | undefined`. Catches the most common real crash (indexing off the end); enable on greenfield day one, on legacy expect a large error wave and stage it
- `exactOptionalPropertyTypes` (TS >=4.4) — distinguishes "absent" from "explicitly undefined"; breaks code that assigns `undefined` to optional props
- `noPropertyAccessFromIndexSignature`, `noImplicitOverride` — cheap to adopt, low churn
- `verbatimModuleSyntax` (TS >=5.0) — forces `import type` for type-only imports; the modern replacement for `isolatedModules` import hygiene (`modules.md`)

Everything else about compiler configuration — target/lib, `module` × `moduleResolution`, paths, monorepos — lives in `tsconfig.md`; import/export mechanics and transpile-only compatibility in `modules.md`.

## Where To Annotate

- Default: annotate exported function signatures (parameters AND return), infer everything inside bodies (rule 3)
- Explicit return types on the public surface also unlock `isolatedDeclarations` (TS >=5.5) and faster declaration emit
- A type parameter must relate at least two positions (two params, or param and return). Used once, it's decoration — replace with `unknown` or the concrete type
- Slow type checking has structural causes and a measurement workflow — `performance.md`

## Output Gates

Before emitting TypeScript, verify:

- No `any` introduced, explicit or implicit — `unknown` where the shape is genuinely open?
- Exported functions annotated, parameters and return?
- Every `as` has a runtime guard above it or a justifying comment?
- Every `switch` over a union ends in an exhaustiveness check?
- External data validated at runtime before its first typed use?
- No `!` where narrowing or `??` would prove it?

## Configuration

User-dependent variables. Defaults apply until the user states a preference; store them in `~/Clawic/data/typescript/config.yaml`.

| Variable | Type | Default | Effect |
|---|---|---|---|
| runtime_target | node \| browser \| bun \| deno \| isomorphic | node | Drives `module`/`moduleResolution` and lib advice in `tsconfig.md` and import-extension rules in `modules.md` |
| project_kind | app \| library | app | Library flips guidance to declaration emit, exports-map types, and wider TS-version support; app defaults to `skipLibCheck` and bundler resolution |
| compile_pipeline | tsc \| transpile-only | transpile-only | transpile-only (esbuild, swc, Babel, bundlers) enforces the single-file-safe subset: no `const enum`, `isolatedModules` rules apply (`modules.md`); tsc lifts those bans |
| validation_library | zod \| valibot \| arktype \| ajv \| none | none | Names the schema library used in boundary-validation examples (`boundaries.md`); none keeps guidance library-neutral |
| ts_version | text (e.g. "5.4") | latest | Gates every `TS >=X.Y`-marked recommendation in this skill: below the mark, the pre-version workaround is offered instead (e.g. below 4.9 an annotation replaces `satisfies`) |

Preference areas to record as the user reveals them:

- **conventions** — `interface` vs `type` default, type naming style, banned features (enums, namespaces, decorators), type-only import style
- **strictness posture** — which beyond-`strict` flags to push proactively, cast tolerance, error-suppression policy
- **tooling** — package manager, typescript-eslint strictness, monorepo layout (project references vs single config), type-test tooling
- **output format** — quick fix vs explained fix, whether to show before/after diffs

## Traps

| Trap | Why it fails | Do instead |
|---|---|---|
| `enum` | The one TS feature with runtime emit; `const enum` breaks under transpile-only compilers | `as const` object + `keyof typeof` (`modules.md`) |
| `Function` or `{}` as a type | `Function` accepts any callable and calls return `any`; `{}` accepts everything except `null`/`undefined` | Exact signature `(a: A) => R`; `Record<string, unknown>` for bags |
| Trusting excess property checks as validation | They fire only on fresh object literals — a value passed through a variable skips them | Runtime validation at boundaries (`boundaries.md`) |
| `// @ts-ignore` | Keeps suppressing after the error is fixed, hiding the next one | `// @ts-expect-error` (TS >=3.9) — errors itself once stale |
| `!` to silence `strictNullChecks` | Each one is an invisible cast and a crash candidate | Narrow, early-return, or `??`; sanctioned only for framework-assigned class fields (`migration.md`) |
| `[key: string]: any` to quiet index errors | Poisons every access on the object with `any` | Precise keys, `Record<K, V>`, or a `Map`; `noUncheckedIndexedAccess` (TS >=4.1) keeps even honest signatures honest |

## Where Experts Disagree

- **`interface` vs `type`.** Default: `interface` for object shapes (merges for augmentation, caches relationships for faster checking), `type` for unions, functions, tuples, and mapped/conditional results. An existing codebase convention beats either.
- **Explicit return types everywhere vs boundary-only.** Boundary-only is the default (rule 3). The everywhere school wins on published libraries and under `isolatedDeclarations` (TS >=5.5), where emit requires them anyway.
- **Runtime validation depth.** Edges-only is the default — validating internally recomputes what the checker already proved. The schema-first school (schema as source of truth, static types inferred from it) wins when one shape crosses many boundaries (`boundaries.md`).

## Related Skills

More Clawic skills, get them at https://clawic.com/skills/typescript (install if the user confirms):

- **javascript** — runtime semantics: coercion, closures, event loop
- **react** — typing components, hooks, and props in practice
- **nodejs** — Node runtime, packaging, and ESM/CJS beyond the type layer
- **deno** — TypeScript-native runtime without a build step

## Feedback

- If useful, star it: https://clawic.com/skills/typescript
- Latest version: https://clawic.com/skills/typescript

Part of [Clawic](https://clawic.com), the verified skill library. Get this skill: https://clawic.com/skills/typescript.

「開發程式設計」分類下的熱門技能

程式設計大神.Skill開發程式設計

【全棧能力】程式設計大神.Skill:面向複雜真實專案的高階全棧程式設計助手。不止生成程式碼,而是從一句目標接手陌生程式碼庫,拆解需求、補齊實現、追到根因、完成重構、聯調前後端,並把結果推進到能執行、能驗證、能交付。覆蓋 Web、後端、指令碼、iOS、安卓、鴻蒙 ArkUI、微信小程式及其他技術棧,支援中英文工程、疑難 Bug、跨模組任務和長任務續做;用構建、日誌、真實入口、裝置或介面證據說明結果。僅問概念時直接回答,要求落地時持續推進到驗收或明確阻塞。

↓ 1125.9萬★ 82u_42bbb65f
程式設計專家Pro.Skill開發程式設計

程式設計專家 Pro:融合程式設計專家 2.0.3 工程專題與程式設計大神的鴻蒙 ArkTS/ArkUI、微信小程式和小遊戲開發資料。用於專案實現、根因除錯、審查、重構、測試、架構效能分析及多端開發驗證。支援自然語言和 @專題標識,按任務讀取包內知識;只問概念時直接回答。

↓ 626.9萬★ 32user_47d655f0
程式設計專家.Skill開發程式設計

程式設計專家.Skill P8級程式設計助手,25年實戰經驗技能Skill,全棧:Java/Php網站/軟體專案、API設計、Bug診斷、程式碼生成、程式碼審查、重構、測試用例、效能基準、技術選型、文件生成、任務拆解、Spec驅動、Karpathy規範、CMS二次開發、前端設計、MySQL/Mariadb、專案知識圖譜,以及工程紀律層(根因除錯硬閉環、階段導航、事故復盤/SLO、威脅建模/供應鏈安全、生產就緒/漸進式釋出、AI編碼治理、面向Agent程式碼可讀性、LLM應用安全)。支援 @標識 顯式呼叫跳過路由。

↓ 600.7萬★ 378user_741dc82b
dev-expert開發程式設計

程式設計專家.Skill P8級程式設計助手,25年實戰經驗技能Skill,全棧:Java/Php網站/軟體專案、API設計、Bug診斷、程式碼生成、程式碼審查、重構、測試用例、效能基準、技術選型、文件生成、任務拆解、Spec驅動、Karpathy規範、CMS二次開發、前端設計、MySQL/Mariadb、專案知識圖譜,以及工程紀律層(根因除錯硬閉環、階段導航、事故復盤/SLO、威脅建模/供應鏈安全、生產就緒/漸進式釋出、AI編碼治理、面向Agent程式碼可讀性、LLM應用安全)。支援 @標識 顯式呼叫跳過路由。

↓ 528.1萬★ 32user_814dbe54
dev-expert-pro開發程式設計

程式設計專家 Pro:融合程式設計專家 2.0.3 工程專題與程式設計大神的鴻蒙 ArkTS/ArkUI、微信小程式和小遊戲開發資料。用於專案實現、根因除錯、審查、重構、測試、架構效能分析及多端開發驗證。支援自然語言和 @專題標識,按任務讀取包內知識;只問概念時直接回答。

↓ 104.7萬★ -user_814dbe54
程式設計專家 Pro開發程式設計

程式設計專家 Pro:融合程式設計專家 2.0.3 工程專題與程式設計大神的鴻蒙 ArkTS/ArkUI、微信小程式和小遊戲開發資料。用於專案實現、根因除錯、審查、重構、測試、架構效能分析及多端開發驗證。支援自然語言和 @專題標識,按任務讀取包內知識;只問概念時直接回答。

↓ 98.2萬★ 1user_28275a78
程式設計專家.Skill開發程式設計

程式設計專家.Skill P8級程式設計助手,25年實戰經驗技能Skill,全棧:Java/Php網站/軟體專案、API設計、Bug診斷、程式碼生成、程式碼審查、重構、測試用例、效能基準、技術選型、文件生成、任務拆解、Spec驅動、Karpathy規範、CMS二次開發、前端設計、MySQL/Mariadb、專案知識圖譜,以及工程紀律層(根因除錯硬閉環、階段導航、事故復盤/SLO、威脅建模/供應鏈安全、生產就緒/漸進式釋出、AI編碼治理、面向Agent程式碼可讀性、LLM應用安全)。支援 @標識 顯式呼叫跳過路由。

↓ 70.1萬★ 6user_613b33ea
Github開發程式設計

用 gh 命令列工具檢視 GitHub 上的 PR 檢查、工作流執行與 API 查詢的技能。

↓ 48萬★ 714Peter Steinberger

Iván 的其他技能

資料月份:2026-10 · 下載/星標數聚合自公開技能註冊庫(ClawHub、SkillHub),按月更新。口徑說明見資料方法。