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 🙏

© 2024 – Pkg Stats / Ryan Hefner

typescript-toolbelt

v0.0.5

Published

Helpers & utility types for TypeScript projects.

Downloads

15

Readme

typescript-toolbelt

Helpers & utility types for TypeScript projects.

Usage

To put type helpers into the global scope:

/// <reference types="typescript-toolbelt/global" />

...or add to your tsconfig's "files" or "include" array:

"files": [
    "node_modules/typescript-toolbelt/global.d.ts"
]

To expose type helpers as a global TT namespace, reference typescript-toolbelt/namespace:

/// <reference types="typescript-toolbelt/namespace" />

...or put it in your tsconfig as shown above.

A few helpers require a runtime value. This will be an identity or no-op function. Thankfully, these should be removed or inlined by a code minifier and/or the JS VM. These must be imported, because it would be messy to attach them to the global object.

Fortunately, if you're using a supported editor, you can reference them in code and the language service will offer to write the import statement for you.

import { narrowLiterals } from 'typescript-toolbelt';

const foo = narrowLiterals(['a', 'b', 'c']);

React-specific helpers should be imported from typescript-toolbelt/react. These can't be loaded by default because they have a peer dependency on @types/react.

Docs

Until I get around to generating a website from the documentation, use tab-complete in your editor to see the list of helpers and flip through their documentation. Or read the source.

Things already bundled in TypeScript

TypeScript already includes a bunch of type declarations you might not be aware of. Here's an incomplete list:

ArrayLike<T> // Minimal Array interface, without all the obscure methods and Symbols.

Partial<T> // T, except all properties are optional
Required<T> // T, except none of the properties are optional

Record<K, T> // object-based map from K to T

Readonly<T> // T, except all properties are readonly
ReadonlyArray<T> // Readonly array.  Type system will forbid assignment to items and accessing methods that mutate, like `push()`
ReadonlyMap<K, V> // Readonly ECMAScript Map
ReadonlySet<V> // Readonly ECMAScript Set

Extract<T, U> // filter a union type T to only the types that extend U
Exclude<T, U> // opposite of Extract; filter union T to only the types that *do not* extend U

NonNullable<T> // Remove `null` and `undefined` from a union type.

ReturnType<F> // Extract the return type of an invokable type (function)
InstanceType<C> // Extract the instance type of a `new`-able type (constructor)

Pick<T, K> // Grab only properties K of interface T.  Useful with `Extract`, `Exclude`, and `keyof`

TODO

  • add DeepReadonly, DeepMutable, DeepPartial, DeepRequired, DeepNonNullable, DeepNullable (any others?)