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

@mmtypes/common

v0.0.1

Published

Common reusable types for TypeScript.

Readme

Common TypeScript types

Collection of common reusable types for TypeScript.

Installation

Install the package

npm install @mmtypes/common
# or
yarn add @mmtypes/common

Import

import type {
  AtLeastOneItem,
  AtLeastOneProperty,
  EmptyObject,
  IfNumberLiteral,
  NumberedTupleSplicer,
  ObjectEntries,
  StringLiteralToCharTuple,
  TupleOfNElements,
} from '@mmtypes/common';

Changelog

v0.0.1

Initial release.

Usage

type AtLeastOneItem:

At least one item from a tuple or an array T is required.

type T1 = AtLeastOneItem<[]>; // [never, ...never[]]
type T2 = AtLeastOneItem<[1]>; // [1, ...1[]]
type T3 = AtLeastOneItem<[1, 2, 3]>; // [1 | 2 | 3, ...(1 | 2 | 3)[]]

const x1: AtLeastOneItem<[1, 2, 3]> = []; // NOT ok
const x2: AtLeastOneItem<[1, 2, 3]> = [2]; // ok
const x3: AtLeastOneItem<[1, 2, 3]> = [3, 1, 2]; // ok
const x4: AtLeastOneItem<[1, 2, 3]> = [3, 1, 2, 4]; // NOT ok

type AtLeastOneProperty:

At least one property from the provided object T is required.

const x1: AtLeastOneProperty<{ a: number; b: number }> = {}; // NOT ok
const x2: AtLeastOneProperty<{ a: number; b: number }> = { a: 1 }; // ok
const x3: AtLeastOneProperty<{ a: number; b: number }> = { b: 2 }; // ok
const x4: AtLeastOneProperty<{ a: number; b: number }> = { a: 1, b: 2, c: 3 }; // NOT ok

type EmptyObject:

Accepts only empty object '{}'.

const x1: EmptyObject = {}; // ok
const x2: EmptyObject = []; // NOT ok
const x3: EmptyObject = { a: 1 }; // NOT ok

type IfNumberLiteral:

eturns Y type if T is number literal and N type if it's not.

type T1 = IfNumberLiteral<number>; // false
type T2 = IfNumberLiteral<1>; // true
type T3 = IfNumberLiteral<1, { a: 1 }, { b: 2 }>; // { a: 1 }

type NumberedTupleSplicer:

Creates tuple of type [NumsTuple[n], ValuesTuple[NumsTuple[n]]] the intersecting keys from ValuesTuple and NumsTuple values. The resulting 0 index tuple element will have the type of NumsTuple[n].

type T1 = NumberedTupleSplicer<['a', 'b', 'c']>; // (["0", "a"] | ["1", "b"] | ["2", "c"])[]
type T2 = NumberedTupleSplicer<['a', 'b', 'c'], [0, 1, 2]>; // ([0, "a"] | [1, "b"] | [2, "c"])[]
type T3 = NumberedTupleSplicer<['a', 'b', 'c', 'd'], ['1', '3', '5']>; // (["1", "b"] | ["3", "d"])[]

type ObjectEntries:

Narrower return type for Object.entries based on the input type, what JS returns and what are the build in types from TypeScript.

WARNING: Do not use this type if you are not certain that the object you iterate over won't change during runtime.

type T1 = ObjectEntries<{ a: number; b: string }>; // (["a", number] | ["b", string])[]
type T2 = ObjectEntries<{ a: 123; b: 'abc' }>; // (["a", 123] | ["b", "abc"])[]
type T3 = ObjectEntries<{}>; // [string, unknown][]
type T4 = ObjectEntries<[]>; // [string, never][]
type T5 = ObjectEntries<'abc'>; // (["0", "a"] | ["1", "b"] | ["2", "c"])[]
type T6 = ObjectEntries<string>; // [string, string][]
type T7 = ObjectEntries<readonly ['a', 'b']>; // (["0", "a"] | ["1", "b"])[]
type T8 = ObjectEntries<[string, number, ...boolean[]]>; // [string, string | number | boolean][]
type T9 = ObjectEntries<number | boolean | bigint>; // [string, any][]

type StringLiteralToCharTuple:

Converts a string literal to a char literal tuple.

type T1 = StringLiteralToCharTuple<'abc'>; // ["a", "b", "c"]

type TupleOfNElements:

Provide a number N to generate numbered tuple of N elements. If AsString is false, the tuple elements are number literals.

type T1 = TupleOfNElements<3>; // ['0','1','2']
type T2 = TupleOfNElements<3, true>; // ['0','1','2']
type T3 = TupleOfNElements<3, false>; // [0,1,2]

License

This project is licensed under the MIT License.