typescript-satisfies-operator

Validate TypeScript object shapes with the satisfies operator while preserving literal types.

Updated Apr 26, 2026
One-click install
npx skills add https://github.com/suwandre/my-opencode-config --skill typescript-satisfies-operator-suwandre
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-satisfies-operator
Source: https://github.com/suwandre/my-opencode-config/tree/main/skills/typescript-satisfies-operator
Command: npx skills add https://github.com/suwandre/my-opencode-config --skill typescript-satisfies-operator-suwandre

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TypeScript developers often want to validate object shapes against a type without changing the inferred type. The satisfies operator lets you validate shapes while preserving literal types, avoiding unintended widening that can break type precision.

Core Features & Use Cases

  • Preserves literal types while validating against a target type
  • Guides when to use satisfies vs type annotations
  • Supports patterns like as const satisfies in common configs and API contracts

Quick Start

Create a small config object using as const and satisfies to validate its shape against a predefined TypeScript type.

Frequently Asked Questions about typescript-satisfies-operator

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate TypeScript object shapes without widening literal types?

The TypeScript satisfies operator validates object shapes against a target type while preserving literal types, preventing unintended widening that breaks type precision in configs and API contracts. Use as const satisfies to enforce validation without losing inference.

When should I use the TypeScript satisfies operator instead of a type annotation?

Use the TypeScript satisfies operator when you need shape validation without overriding inferred literal types. Type annotations widen values to their base types, whereas satisfies ensures an object matches a structure while retaining precise literal type information for type-heavy development.

Does the TypeScript satisfies operator require a specific compiler version?

Yes, the TypeScript satisfies operator requires TypeScript 4.9 or higher. It works by validating that an expression matches a target type without widening, making it essential for complex type-inference scenarios and literal type preservation in modern TypeScript codebases.

What's the best way to preserve literal types in TypeScript configuration objects?

Combine as const with the TypeScript satisfies operator to preserve literal types while validating configuration shapes. This pattern ensures your config objects enforce strict structural validation against predefined types without losing precise literal type inference during type-heavy development.

Why does my TypeScript type annotation widen literal types in my API client?

TypeScript type annotations widen literal values to their base types during assignment. To avoid this while still validating shapes, use the satisfies operator instead, which checks structural conformity against your API contracts without discarding the precise literal type inference.

Can I use satisfies with as const for complex type inference in TypeScript?

Yes, combining as const satisfies in TypeScript preserves readonly literal types while enforcing shape validation. This pattern is highly effective for API clients and configuration objects where both strict structural validation and precise literal type inference are required.