跳到正文
cccskills
免费在 GitHub 公开

no-bare-casts

Review TypeScript type assertions, which tell the compiler to treat a value as a chosen type. Replace bare casts with better types or runtime checks, and use explicit helpers with specific reasons when an escape hatch remains necessary.

中文简介正在准备中。当前显示英语简介。

原文查看原文说明

Writing `as` in TypeScript or TSX production code, modifying a file that contains a bare `as` cast, silencing a type error with a cast, encountering `as unknown as`, or reviewing a cast site.

查看安装方法

适用场景

  • Review an assertion used to silence a type error
  • Replace a double assertion such as as unknown as
  • Reduce existing casts while editing production files
  • Document a cast that cannot be eliminated

包含的文件(1)

  • SKILL.md2.8 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

No bare as casts

Any bare as in production TypeScript is a signal to stop and work through the decision tree below. Test files (*.test.ts, *.test-d.ts, test/**/*.ts) are exempt — tests use as for stubbing and type assertions and that's fine.

Decision tree

Work through these in order before writing or keeping a cast:

  1. Tighten the input type. Can the parameter, generic bound, or return type at the source be made more specific so the cast is unnecessary?
  2. Add a runtime check. Can a type predicate (function isUser(x): x is User) narrow the type at runtime, eliminating the cast?
  3. Restructure a generic. Can a bound or constraint carry the needed information, making the cast unnecessary?
  4. Use satisfies. expr satisfies T checks the type without coercing it and is unaffected by this rule. Prefer it when you want a type-check, not a coercion.
  5. Use castAs<T>(value). When the value already satisfies T and the assertion is purely declarative, castAs is the right form.
  6. Only if none of the above: use blindCast<T, "Reason">(value). The Reason literal must name the specific compromise in language a reviewer can evaluate.

Import

import { blindCast, castAs } from '@internal/utils/casts';

Helper signatures

// Escape hatch — the value is genuinely opaque or unrelated to the target type.
// The Reason literal documents the compromise; the reviewer evaluates it.
function blindCast<TargetType, Reason extends string>(input: unknown): TargetType

// Declarative assertion — the value already satisfies T at runtime.
function castAs<T>(value: T): T

The Reason bar

blindCast is the auditable escape hatch of last resort — not a convenience wrapper. Reach for it only after the decision tree above has been exhausted. The second type argument must be a string literal that a reviewer can act on:

// ✅  Names the specific constraint
blindCast<User, "deserialized from contract validator; shape has already been checked">(raw)

// ❌  Adds no information — reviewer has nothing to evaluate
blindCast<User, "trust me">(raw)

A vague reason is the reviewer's signal to push back and the author's signal to revisit the type design.

"Convert when you touch"

When you touch a file that contains a bare as cast — even as part of unrelated work — convert it to one of the accepted forms or eliminate it. The CI ratchet (pnpm lint:casts) rejects per-PR cast-count increases; converting on contact is how the total comes down over time.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Review and rewrite architecture decision records, documents that explain design choices, from a newcomer’s perspective. Identify missing context, buried decisions, and temporary details, then reorganize each document so future readers can follow the reasoning.

中文简介正在准备中。当前显示英语简介。

  • Reviewing design decisions from a new team member’s perspective
  • Making an ADR’s decision and reasoning easier to follow
  • Removing temporary project context from long-lived records
prisma/orm4.8万2026年10月17日 更新

Refactor TypeScript code that handles several variants in multiple places using frozen classes and a Visitor interface, which defines a handler for each variant. This helps type checking expose missing handlers when new variants are added.

中文简介正在准备中。当前显示英语简介。

  • Refactor a union type with repeated switch statements
  • Design commands or nodes that need several kinds of processing
  • Catch missing handlers when adding a new variant
prisma/orm4.8万2026年10月17日 更新

Update Biome packages with pnpm, align configuration filenames and schema versions across the repository, and run the configured checks and fixes. Receive a report of remaining issues, with optional further fixes subject to agreement.

中文简介正在准备中。当前显示英语简介。

  • Updating Biome to a specified version
  • Aligning configuration files after dependency updates
  • Checking for issues introduced by a Biome update
prisma/orm4.8万2026年10月17日 更新

Prepare and open a pull request for an external contribution to prisma/orm. Check contribution rules, change scope, tests, and contributor signoffs, then draft the title and explanation for approval before submitting from a fork.

中文简介正在准备中。当前显示英语简介。

  • Submitting a Prisma contribution from a fork
  • Checking tests and scope before requesting review
  • Verifying contributor signoffs on every commit
prisma/orm4.8万2026年10月17日 更新

create-pr

免费

Create GitHub pull requests for Prisma 8 with Linear ticket IDs in their titles. Turn branch changes into a clear description covering concrete examples, design decisions, behavior changes, and testing evidence for reviewers.

中文简介正在准备中。当前显示英语简介。

  • Submitting branch changes for review
  • Linking a pull request to a Linear ticket
  • Explaining design decisions and behavior changes
prisma/orm4.8万2026年10月17日 更新

Draft Prisma 8 release notes from merged PRs since the previous published release. Select user-facing changes, put breaking changes first, link migration guidance and PR evidence, and mirror the notes in CHANGELOG.md.

中文简介正在准备中。当前显示英语简介。

  • Draft notes for a stable or RC release
  • Summarize changes since the previous published release
  • Explain breaking changes with migration guidance
prisma/orm4.8万2026年10月17日 更新

查看 prisma 的全部技能

报告此技能的问题