Introduction
type-fest provides a curated, well-tested collection of TypeScript utility types that fill gaps in the built-in utility types. Maintained by Sindre Sorhus, it covers deep partial, readonly, JSON types, string manipulation, and dozens more patterns commonly needed across TypeScript projects.
What type-fest Does
- Provides deep recursive versions of built-in types like PartialDeep and ReadonlyDeep
- Offers strict variants of Extract, Exclude, and Omit that catch typos at compile time
- Includes JSON-related types for parsing and serialization safety (JsonValue, JsonObject)
- Supplies string literal manipulation types like CamelCase, KebabCase, and Split
- Adds array utilities like FixedLengthArray, ArraySlice, and LastArrayElement
Architecture Overview
type-fest is a pure type-level library with zero runtime code. Each type is defined in its own source file, tree-shakeable by design. The library requires TypeScript 5.9 or later and strict mode enabled. Types are organized by category and exported from a single entry point for convenient imports.
Self-Hosting & Configuration
- Install via npm:
npm install type-fest - Import types using
import typesyntax only (no runtime footprint) - Requires
strict: truein tsconfig.json - Requires TypeScript 5.1 or later (5.9 recommended for latest features)
- Works with any bundler or runtime since it emits no JavaScript
Key Features
- Over 200 carefully designed utility types
- Zero runtime overhead since every export is a pure type
- Strict mode variants that enforce exact key matching
- Extensive JSDoc documentation with inline examples for every type
- Battle-tested across thousands of npm packages
Comparison with Similar Tools
- ts-toolbelt — larger library with 300+ types; heavier, more complex API surface
- utility-types — smaller collection focused on mapped and conditional types; less maintained
- ts-essentials — overlapping scope with deep partial and readonly types; fewer string utilities
- TypeScript built-in utilities — Partial, Pick, Omit, etc.; lacks deep variants and string types
- simplytyped — lightweight alternative; discontinued
FAQ
Q: Does type-fest add any runtime code to my bundle? A: No. Every export is a TypeScript type, removed entirely during compilation.
Q: Which TypeScript version is required? A: TypeScript 5.1 or later with strict mode enabled. Some newer types require 5.9.
Q: Can I use individual types without importing the whole package?
A: Yes. Use import type { CamelCase } from 'type-fest' and your bundler will include only the type reference, which compiles away.
Q: How is PartialDeep different from the built-in Partial? A: The built-in Partial only makes top-level properties optional. PartialDeep recursively makes every nested property optional as well.