agentsclimarketplace

Ban type assertions

Skill zacharygcook/agent-skills/skills/ban-type-assertions

Enforce a TypeScript policy that bans `as` type assertions and replace casts with compiler-verified narrowing or runtime validation. Use when introducing the ESLint rule, removing violations, reviewing assertion workarounds, or designing typed data boundaries.From its SKILL.md

Install
npx -y skills add zacharygcook/agent-skills --skill ban-type-assertions

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

2.4 KB, 455 tokens by cl100k_base, as published. Nobody here has run it

Ban Type Assertions

Configure @typescript-eslint/consistent-type-assertions with assertionStyle: "never", then replace assertions with code the compiler or runtime can verify. Treat as const according to the repository's explicit policy.

Decision Order

1. Validate external data

Parse JSON, network responses, storage, database rows, messages, and other untrusted inputs with the repository's runtime schema library.

// Avoid
const value = JSON.parse(raw) as Payload

// Prefer
const value = PayloadSchema.parse(JSON.parse(raw))

Use non-throwing parse APIs where failure needs structured handling or request context.

2. Narrow with control flow

Use discriminated unions, exhaustive switch, typeof, instanceof, and in when TypeScript can prove the result.

if (error instanceof Error && "code" in error) {
  handleCode(error.code)
}

3. Improve the API or types

Fix overly broad return types, generic inference, duplicate domain types, and missing package contracts. Prefer satisfies when checking an object without changing its inferred type.

4. Document a genuine exception

Use a narrow lint suppression only for an unavoidable library/type-system gap. Explain why it is safe and why normal narrowing cannot work. Do not quietly raise a ratchet threshold.

Avoid Disguised Assertions

A custom predicate returning value is T is still an assertion unless its checks fully establish T. Use schema validation for rich object shapes. Do not replace one cast with a weak guard that only checks one property.

Rollout

  1. Locate all TypeScript packages and their ESLint configurations.
  2. Enable the rule consistently.
  3. Inventory violations and classify boundary, narrowing, API-design, and unavoidable cases.
  4. Fix violations package by package.
  5. Add a CI check or zero-tolerance report if repository lint scope can miss files.
  6. Run lint, typecheck, focused tests, the full suite when practical, and unused-export checks after shared-type changes.

Test fixtures must satisfy the same schemas as production data; do not disable the rule in tests merely to keep incomplete mocks.

What ships with it: 1 file

288 B alongside SKILL.md

agents/

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.