typescript-advanced-type-guards

typescript-advanced-type-guards is a skill for Claude Code from pantheon-org/tekhne. It costs 123 tokens per session (1,937 once invoked), scanned A, original, MIT.

A guide to TypeScript checks that confirm a value's type while the program runs, then let the compiler use that information. It also covers safely handling every possible case in a grouped set of values.

In plain words
What is it for?
Use it to write custom checks for API or user data, narrow union types, validate branded values, and make switch statements handle every case.
Why use it?
It prevents code from trusting an incorrect type or silently missing a case. This reduces errors when data comes from outside the program or when new states are added.

Skill for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Good fit Use it to write custom checks for API or user data, narrow union types, validate branded values, and make switch statements handle every case.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/pantheon-org/tekhne/type-guards
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add pantheon-org/tekhne --skill type-guards
Clone the repo
git clone --depth 1 https://github.com/pantheon-org/tekhne

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for typescript-advanced-type-guards

README.md
[![agentmods](https://agentmods.dev/badge/skills/pantheon-org/tekhne/type-guards/github.svg)](https://agentmods.dev/skills/pantheon-org/tekhne/type-guards)
Your own site
<a href="https://agentmods.dev/skills/pantheon-org/tekhne/type-guards"><img src="https://agentmods.dev/badge/skills/pantheon-org/tekhne/type-guards/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for typescript-advanced-type-guards

Your own site · 80×15
<a href="https://agentmods.dev/skills/pantheon-org/tekhne/type-guards"><img src="https://agentmods.dev/badge/skills/pantheon-org/tekhne/type-guards.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 123 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,937 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00123 $0.01937
Opus 5.5 $0.00049 $0.00775
Sonnet 5.5 $0.00025 $0.00387
Haiku 4.5 $0.00012 $0.00194

Measured 24d ago against content hash e45d176a0cc3, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

typescript-advanced-type-guards scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 24d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/development/typescript-advanced/type-guards/SKILL.md · 215 lines

How it starts

The opening of the file, as written. The whole thing — 215 lines — stays where its author put it; the contents beside it link to each section on GitHub.

TypeScript Type Guards

Runtime type guards and narrowing: the compile-time type system backed by an actual runtime check, so a type guarantee is real rather than asserted.

Mindset

A type guard is a promise the compiler will hold you to only if the runtime check underneath it is honest. Never reach for any or an unchecked as assertion as a shortcut past a type error — both disable the exact safety net a guard exists to provide, and the error they suppress almost always points at a real design gap. Prefer narrowing a value before use over asserting its type after the fact: if (typeof x !== "string") throw ... gives the compiler a real fact to reason from; x as string gives it nothing but your word. Verify a narrowing actually narrows by re-running tsc --noEmit after the change — a guard that looks correct can still fail to narrow if its predicate doesn't match the shape TypeScript expects. Every union that models a real set of states deserves an exhaustive switch with a never-typed default branch, so adding a new state without updating every handler is a compile error, not a silent gap.

When to Apply

Use this skill when:

  • Replacing an unsafe as assertion with a runtime check that narrows for real
  • Writing a custom type predicate (function is*(x): x is T)
  • Modeling impossible field combinations out of existence with a discriminated union
  • Adding an assertion function (asserts value is T) to validate and narrow in one call
  • Creating branded/nominal types with a validating factory function
  • Adding exhaustiveness checking to a switch over a union so new variants can't be silently unhandled
  • Fixing "Object is possibly 'undefined'" without reaching for a non-null assertion (!)

Use When

  • "How do I fix this TypeScript compile error without an as assertion?"
  • "How do I check the shape of an unknown value at runtime?"
  • "How do I make my switch statement error if I add a new case and forget to handle it?"
  • "How do I stop two IDs of the same primitive type from being mixed up?"

Read the full file on GitHub · 215 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 24d ago First seen · 215 lines · 123 tokens per session scan A e45d176a0cc3

Subscribe to this mod's changes

typescript-advanced-type-guards is a skill published in the GitHub repository pantheon-org/tekhne (10 stars, last pushed yesterday), licensed MIT. It adds 123 tokens to every session and 1,937 once invoked, about $0.0005 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-24.

Related

Other skills, from other repositories

developing-genkit-js

Develop AI-powered applications using Genkit in Node.js/TypeScript. Use when the user asks about Genkit, AI agents, flows, or tools in JavaScript/TypeScript, or when encountering Genkit errors, validation issues, type errors, or API problems.

google/skills · 60 tokens

antfu

Anthony Fu's opinionated tooling and conventions for JavaScript/TypeScript projects. Use when setting up new projects, configuring ESLint/Prettier alternatives, monorepos, library publishing, or when the user mentions Anthony Fu's preferences.

antfu/skills · 52 tokens

setup-ts-deep-modules

A setup for TypeScript packages that hides their implementation behind files at the package root. Dependency-cruiser checks that outside code uses these entry points, prevents dependency cycles, and keeps internal folders private.

devcxl/mattpocock-skills-zh · 49 tokens

aws-lambda-typescript-integration

Provides AWS Lambda integration patterns for TypeScript with cold start optimization. Use when creating or deploying TypeScript Lambda functions, choosing between NestJS framework and raw TypeScript approaches, optimizing cold starts, configuring API Gateway or ALB integration, or implementing serverless TypeScript…

giuseppe-trisciuoglio/developer-kit · 95 tokens

loom-typescript

TypeScript language expertise for type-safe, production-quality code.

cosmix/loom · 16 tokens

senior-frontend

Frontend development for React 19, Next.js 15, TypeScript, and Tailwind CSS v4 / Pengembangan frontend dengan React 19, Next.js 15, TypeScript, dan Tailwind CSS v4.

roedyrustam/vibes-plug · 50 tokens