npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

types-belt

v1.0.5

Published

A comprehensive collection of TypeScript utility types for building robust and maintainable applications

Downloads

20

Readme

Types-Belt 🎯

A comprehensive collection of TypeScript utility types for building robust and maintainable applications. Types-Belt provides a wide range of utility types that help you write better TypeScript code with improved type safety and developer experience.

✨ Features

  • Object Utilities: Transform object properties (Partial, Required, Readonly, Pick, Omit, etc.)
  • Function Utilities: Extract function types, parameters, and return types
  • Array & Tuple Utilities: Advanced array and tuple manipulation types
  • Conditional Types: Type guards and conditional type utilities
  • Production Ready: Well-tested and documented for production use
  • Zero Dependencies: Pure TypeScript with no runtime dependencies

🚀 Installation

npm install types-belt
yarn add types-belt
pnpm add types-belt

📖 Usage

Object Utility Types

import type { Partial, Required, Readonly, Pick, Omit, Record } from 'types-belt';

interface User {
  id: number;
  name: string;
  email: string;
  password: string;
}

// Make all properties optional
type PartialUser = Partial<User>;
// Result: { id?: number; name?: string; email?: string; password?: string; }

// Make all properties required
type RequiredUser = Required<User>;
// Result: { id: number; name: string; email: string; password: string; }

// Make all properties readonly
type ReadonlyUser = Readonly<User>;
// Result: { readonly id: number; readonly name: string; readonly email: string; readonly password: string; }

// Pick specific properties
type UserPublic = Pick<User, 'id' | 'name' | 'email'>;
// Result: { id: number; name: string; email: string; }

// Omit specific properties
type UserWithoutPassword = Omit<User, 'password'>;
// Result: { id: number; name: string; email: string; }

// Create a record type
type UserRoles = Record<'admin' | 'user' | 'guest', boolean>;
// Result: { admin: boolean; user: boolean; guest: boolean; }

Function Utility Types

import type { ReturnType, Parameters, FirstParameter, LastParameter } from 'types-belt';

type MyFunction = (name: string, age: number) => Promise<boolean>;

// Extract return type
type ReturnType = ReturnType<MyFunction>; // Promise<boolean>

// Extract parameter types
type Params = Parameters<MyFunction>; // [string, number]

// Extract first parameter
type FirstParam = FirstParameter<MyFunction>; // string

// Extract last parameter
type LastParam = LastParameter<MyFunction>; // number

Array & Tuple Utility Types

import type { ArrayElement, Tuple, FirstElement, LastElement } from 'types-belt';

// Extract element type from array
type StringArray = string[];
type ElementType = ArrayElement<StringArray>; // string

// Create tuple with specific length
type StringTuple3 = Tuple<string, 3>; // [string, string, string]

// Extract first and last elements
type MyTuple = [string, number, boolean];
type First = FirstElement<MyTuple>; // string
type Last = LastElement<MyTuple>; // boolean

Conditional Utility Types

import type { Is, Extends, If, IsUnion, IsArray, IsFunction } from 'types-belt';

// Check if types are exactly equal
type IsString = Is<string, string>; // true
type IsNumber = Is<string, number>; // false

// Check if type extends another
type CanAssign = Extends<string, string | number>; // true

// Conditional type selection
type Result = If<true, string, number>; // string

// Type guards
type IsUnionType = IsUnion<string | number>; // true
type IsArrayType = IsArray<string[]>; // true
type IsFunctionType = IsFunction<() => void>; // true

🧪 Testing

Run the test suite to ensure all types work correctly:

# Run tests in watch mode
npm test

# Run tests once
npm run test:run

# Run tests with coverage
npm run test:coverage

# Type checking
npm run type-check

🏗️ Building

Build the package for distribution:

npm run build

This will create the following outputs in the dist/ directory:

  • types-belt.es.js - ES Module format
  • types-belt.cjs - CommonJS format
  • index.d.ts - TypeScript declarations
  • Source maps

📦 Publishing

Before publishing to npm, the package will automatically:

  1. Build the project
  2. Run all tests
  3. Ensure everything passes
npm publish

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by the TypeScript community's need for better utility types
  • Built with modern TypeScript features and best practices
  • Tested with Vitest for reliable type validation

Made with ❤️ for the TypeScript community