Type-Fest

5.6.0 · active · verified Sun Apr 19

Type-Fest is a comprehensive collection of essential TypeScript utility types designed to simplify complex type manipulations and enhance type safety in modern TypeScript projects. Currently stable at version 5.6.0, the library maintains an active release cadence, frequently introducing new types and improving existing ones with minor and patch updates. It serves as a valuable resource for developers seeking robust, well-tested types that address common TypeScript patterns, often providing functionalities that many believe should be part of TypeScript's standard library. Key differentiators include its focus on practical, real-world utility types, its explicit requirement for TypeScript >=5.9 and ESM (ECMAScript Modules) environments, and the recommendation to enable `strict: true` in `tsconfig.json` for optimal usage. The library is also noteworthy for allowing developers to copy and paste types directly into their projects without attribution, promoting broad adoption.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the usage of 'Except', 'Merge', and 'Simplify' types to create new, refined types from existing interfaces, showcasing type composition.

import type {Except, Merge, Simplify} from 'type-fest';

interface User {
  id: string;
  name: string;
  email: string;
  createdAt: Date;
  updatedAt?: Date;
}

interface UserProfile {
  bio: string;
  website?: string;
}

// Create a new user type that excludes 'id' and 'createdAt'
type NewUser = Except<User, 'id' | 'createdAt'>;

// Merge the new user type with a profile to create a complete user
type FullUser = Simplify<Merge<NewUser, UserProfile>>;

const newUser: FullUser = {
  name: 'Alice Wonderland',
  email: 'alice@example.com',
  bio: 'Exploring type safety in Wonderland.',
  website: 'https://alice.example.com'
};

console.log(newUser);

// Demonstrating a common pattern with strict mode
// Type-fest types are designed with strict mode in mind.
// For example, if 'updatedAt' was not optional and not provided, 
// TypeScript would catch the missing property if strict: true is enabled.
const partialUserUpdate: Partial<NewUser> = { name: 'Alice Smith' };
console.log(partialUserUpdate);

view raw JSON →