type-level-error-messages
Installation
SKILL.md
Type-Level Error Messages
Related Skills: See
typescriptfor general TypeScript conventions. Seearktypefor runtime regex validation and where this pattern surfaces in arktype itself.
When to Apply This Skill
Use this pattern when you need to:
- Constrain object keys, string literals, or other literal-type inputs in a helper function and surface a readable error at the call site.
- Replace a
neverorstringreturn in a constraint type with something that points at the bad value. - Match the way
arktype's internalErrorMessage<M>types behave: visible message, invisible brand. - Give app authors edit-site feedback on shape/format rules (snake_case keys, slug formats, semver strings) without forcing every consumer to call a separate
validate()step.
The pattern in one example
// 1. Predicate on the literal type.
type IsSnakeCase<S extends string> = /* recursive template literal walk */;