The as const assertion creates the narrowest possible type from a value. Here's how to use it.
Basic Usage#
Arrays and Tuples#
Enum-like Constants#
Immutable Objects#
Function Parameters#
Route Definitions#
Action Types (Redux-like)#
Validation Schemas#
Event Maps#
Combining with satisfies#
Best Practices#
Usage:
✓ Use for enum-like constants
✓ Use for configuration objects
✓ Use for route definitions
✓ Use for action types
Benefits:
✓ Narrowest possible types
✓ Deep readonly
✓ Literal type inference
✓ Better autocomplete
Patterns:
✓ Combine with typeof
✓ Extract union types
✓ Use with satisfies
✓ Create type-safe enums
Avoid:
✗ On mutable data
✗ When you need assignment
✗ For temporary values
✗ Overusing everywhere
Conclusion#
The as const assertion creates the narrowest literal types and makes values deeply readonly. Use it for configuration, constants, enum alternatives, and action types. Combine with typeof and keyof to extract useful types, and use satisfies for validation while preserving literal types.