Skip to content
Back to skills

Principle Type System Discipline

ASecurity

Use when designing types, reviewing signatures, or writing statically typed code. Have the compiler refuse impossible states, confused primitives, and unhandled variants, and parse outside data where it enters.

  • 1,531 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 7, 2026
ai-agentstypescriptrustgoapidatabasesecurity

Works with

  • api

Security analysis

A100/100

Scanned November 7, 2026

npx -y skills add hashgraph-online/awesome-codex-plugins --skill principle-type-system-discipline --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Principle Type System Discipline?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Principle Type System Discipline
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hashgraph-online-principle-type-system-discipline/badge)](https://www.skillsdirectory.com/skills/hashgraph-online-principle-type-system-discipline)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: principle-type-system-discipline
description: Use when designing types, reviewing signatures, or writing statically typed code. Have the compiler refuse impossible states, confused primitives, and unhandled variants, and parse outside data where it enters.
disable-model-invocation: true
---

# Type system discipline

Let the type checker refuse impossible states, swapped primitives, and variants nobody handles. Design types so error cases and special cases cannot arise, rather than adding handlers for them.

## When it applies

Designing types, reviewing a function signature, and writing in any statically typed language. In an untyped language, apply the same intent with parse functions and runtime schemas.

## What to do

1. Brand semantic primitives. Values that share a primitive but mean different things get distinct types: a branded intersection in TypeScript, a newtype in Rust or Haskell, a distinct type in Go. `UserId` and `TenantId` are both strings, and a function that takes both in the wrong order is a cross-tenant access bug the compiler could have caught. Validate once at construction and trust the type afterward.
2. Consider data from outside the program untyped until a parser has accepted it. That covers IPC messages, JSON documents, RPC payloads, command-line arguments, config files, environment variables, database rows, and tool-call arguments produced by a model. Each boundary has a parse function that produces the typed model.
3. Derive types from authoritative schemas (protocol buffers, OpenAPI, GraphQL schemas, database migrations, design-token files).
4. Make illegal states unrepresentable. Use a discriminated union in place of an object with optional fields that are only valid in certain combinations.
5. Handle variants exhaustively, so adding a variant is a compile error at every unhandled site. Add a new `Permission` variant and the compiler lists every policy check that has not decided what to do with it.
6. Let types carry security properties: if only the sanitizer can construct `SanitizedHtml`, a template that accepts only that type cannot render raw input.
7. For TypeScript syntax specifics, follow the [typescript-best-practices](../typescript-best-practices/SKILL.md) skill.

## The failure it prevents

ID mix-ups, unvalidated external data deep in the system, drift between hand-rolled types and the real schema, and new variants that nothing handles.

## Done when

The compiler rejects the illegal states in question.

Related: [principle-boundary-discipline](../principle-boundary-discipline/SKILL.md), [principle-encode-lessons-in-structure](../principle-encode-lessons-in-structure/SKILL.md), [principle-model-the-domain](../principle-model-the-domain/SKILL.md), [typescript-best-practices](../typescript-best-practices/SKILL.md).

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.