type-fest
Collection of essential TypeScript utility types beyond the built-ins, from Merge to JsonValue.
Official Documentation ↗v5.10.0. Check the official docs for the latest API surface.Installation
npm install type-festpnpm add type-festMethods
No methods match this filter.
Collection of essential TypeScript utility types beyond the built-ins, from Merge to JsonValue.
Overview
type-fest collects the utility types TypeScript itself has not shipped: Merge and its conflict semantics, SetRequired and SetOptional for surgical field changes, deep variants of Partial and Readonly, and precise JSON shapes with JsonValue and Jsonify.
Because everything is a pure type, the package costs zero runtime. It slots into existing type-level code without build changes and is a common dependency for libraries exposing strict public typings.
Core Methods
The most frequently used entry points, with signatures and runnable examples:
Merge— Combines two object types with B overriding conflicting keys, unlike intersections that keep both.SetRequired / SetOptional— Narrows or widens specific keys of a type without rewriting the whole interface.PartialDeep / ReadonlyDeep— Applies Partial or Readonly recursively through nested objects, arrays, and maps.JsonValue / Jsonify— Describes exactly what JSON can represent, and Jsonify converts a type to its JSON shape.
Usage Notes
- Prefer these battle-tested utilities over hand-rolled conditional types.
- Use Jsonify on API response types to model what serialization actually delivers.
- Pin versions to your TypeScript release line to avoid surprise type errors.
Common Pitfalls
- type-only imports keep the dependency honest; a value import would fail since there is no runtime.
- Deep utilities can explode on highly recursive types with bad error messages.
- Upgrade type-fest alongside TypeScript, mismatched pairs surface as cryptic syntax errors.
FAQ
- Is type-fest a runtime library?
- No. It is types only: importing it adds no code to your bundle. It compiles away, which is why it appears in typeDependencies discussions rather than bundle size reports.
- How does Merge differ from intersections?
- A & B keeps both members of conflicting keys, producing never or union surprises. Merge resolves conflicts in favor of the second type, matching how people expect overrides to behave.
- Which TypeScript version do I need?
- type-fest tracks recent TypeScript releases, and its type-level features use newer syntax. Check the README compatibility table; pin the type-fest version matching your toolchain rather than always taking latest.
Report a problem with this API docOpens a pre-filled issue on GitHub.