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

@dhlx/types

v0.0.4

Published

typescript 工具类型

Readme

@dhlx/types

A collection of useful TypeScript utility types to enhance your type system experience. These types cover various scenarios such as deep merging, value extraction, permutations, and more. You can easily import them for better type manipulation in your projects.

Installation

You can install the package via npm or yarn:

npm install @dhlx/types
# or
yarn add @dhlx/types

Exported Types

This package includes the following utility types:

UnionToIntersection<U>

Converts a union type into an intersection type.

type Result = UnionToIntersection<{ a: string } | { b: number }>;
// Result: { a: string } & { b: number }

AllCombinations<S extends string>

Generates all possible combinations of characters from a string.

type Result = AllCombinations<'abc'>;
// Result: '' | 'a' | 'b' | 'c' | 'ab' | 'ac' | 'bc' | 'abc'

CrossJoin<A, B>

Combines two string types A and B into a single string type by concatenating them.

type Result = CrossJoin<'a', 'b'>;
// Result: 'ab'

Flatten<T, Prefix extends string = ''>

Flattens a nested object type into a single level, with keys as dot-notation paths.

type Result = Flatten<{ a: { b: { c: number } } }>;
// Result: { 'a.b.c': number }

DeepMerge<T, U>

Deeply merges two types T and U, merging nested objects recursively.

type Result = DeepMerge<{ a: { b: number } }, { a: { c: string } }>;
// Result: { a: { b: number, c: string } }

DeepPromiseValueType<T>

Extracts the resolved value type of a Promise, recursively resolving nested promises.

type Result = DeepPromiseValueType<Promise<Promise<number>>>;
// Result: number

Replace<T extends string, S extends string, M extends string>

Replaces all occurrences of a substring S in a string T with the string M.

type Result = Replace<'hello world', 'world', 'everyone'>;
// Result: 'hello everyone'

Unique<T>

Extracts unique values from a union type, removing duplicates.

type Result = Unique<[1, 2, 2, 3, 3, 4]>;
// Result: [1, 2, 3, 4]

DeepPick<T, S extends string>

Recursively picks properties from a nested object type, based on a dot-notation string path.

type Result = DeepPick<{ a: { b: { c: number } } }, 'a.b.c'>;
// Result: { c: number }

DeepReadonly<T>

Makes all properties of a type T and its nested properties readonly.

type Result = DeepReadonly<{ a: { b: number } }>;
// Result: { readonly a: { readonly b: number } }

FilterKeys<T, U>

Filters the keys of an object T where the corresponding value type extends U.

type Result = FilterKeys<{ a: number, b: string, c: boolean }, string>;
// Result: 'b'

OmitByType<T, U>

Omit the properties of an object T that have a value type extending U.

type Result = OmitByType<{ a: number, b: string, c: boolean }, string>;
// Result: { a: number, c: boolean }

Permutation<T extends string>

Generates all possible permutations of a string T.

type Result = Permutation<'abc'>;
// Result: 'abc' | 'acb' | 'bac' | 'bca' | 'cab' | 'cba'

Reverse<T extends unknown[]>

Reverses a tuple or array type T.

type Result = Reverse<[1, 2, 3]>;
// Result: [3, 2, 1]

Subsequences<T extends string>

Generates all subsequences of a string T.

type Result = Subsequences<'abc'>;
// Result: '' | 'a' | 'b' | 'c' | 'ab' | 'ac' | 'bc' | 'abc'

Unique<T>

Ensures that the values of a union type T are unique.

type Result = Unique<[1, 'a', 2, 'b', 1]>;
// Result: [1, 'a', 2, 'b']

GetOptional<T extends object>

Extracts the properties of an object type T that are optional.


type Result = GetOptional<{ a: number, b?: string, c?: boolean }>;
// Result: 'b' | 'c'

DeepPartial<T>

Makes all properties of a type T and its nested properties optional recursively.

type Result = DeepPartial<{ a: { b: { c: number } } }>;
// Result: { a?: { b?: { c?: number } } }

Usage Example

import { UnionToIntersection, AllCombinations, DeepMerge } from 'typescript-utils';

type Result = UnionToIntersection<{ a: string } | { b: number }>;
// Result: { a: string } & { b: number }

type Combos = AllCombinations<'abc'>;
// Combos: '' | 'a' | 'b' | 'c' | 'ab' | 'ac' | 'bc' | 'abc'

type Merged = DeepMerge<{ a: { b: number } }, { a: { c: string } }>;
// Merged: { a: { b: number, c: string } }

License

MIT License. See LICENSE for more information.