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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wentools/result

v0.1.3

Published

TypeScript-first Result type with literal error inference

Readme

@wentools/result

A TypeScript-first wrapper around neverthrow that adds literal type inference and error composition patterns.

Why This Exists

neverthrow is excellent for Result-based error handling, but creating typed errors requires boilerplate:

// With plain neverthrow
import { err } from 'neverthrow'

// You need `as const` or explicit types to preserve the literal
const result = err({ type: 'not_found' as const, message: 'User not found' })

This library fixes that with TypeScript 5.0+ const type parameters:

// With @wentools/result
import { err } from '@wentools/result'

// Literal type is inferred automatically
const result = err('not_found', 'User not found')
// Type: Err<never, { type: 'not_found'; message: string }>

It also provides utilities for:

  • Defining error types concisely
  • Extracting and composing error types from functions
  • Runtime Result detection without importing neverthrow types

Install

# JSR (recommended)
npx jsr add @wentools/result

# Deno
deno add jsr:@wentools/result

Usage

Basic Error Creation

import { err, ok, type Result, type ErrorType } from '@wentools/result'

// Define error types concisely
type UserNotFoundError = ErrorType<'user_not_found'>
type InvalidEmailError = ErrorType<'invalid_email', { email: string }>

// Create Results with inferred literal types
const getUser = (id: string): Result<User, UserNotFoundError> => {
  const user = users.get(id)
  if (!user) {
    return err('user_not_found', `User ${id} not found`)
  }
  return ok(user)
}

// Add context to errors
const validateEmail = (email: string): Result<string, InvalidEmailError> => {
  if (!email.includes('@')) {
    return err('invalid_email', 'Email must contain @', { email })
  }
  return ok(email)
}

Async Chains

import { errAsync, okAsync, type ResultAsync } from '@wentools/result'

const createUser = (data: UserData): ResultAsync<User, CreateError> => {
  return validateEmail(data.email)
    .asyncAndThen((email) =>
      checkEmailUnique(email)
        .andThen(() => insertUser({ ...data, email }))
    )
}

Error Type Composition

import { type ExtractFnError } from '@wentools/result'

// Extract and combine error types from multiple functions
type ServiceError =
  | ExtractFnError<typeof getUser>
  | ExtractFnError<typeof validateEmail>
  | ExtractFnError<typeof createUser>

Runtime Type Check

import { isResult } from '@wentools/result'

const handle = (value: unknown) => {
  if (isResult(value)) {
    if (value.isErr()) {
      console.error(value.error)
    }
  }
}

API

Functions

| Function | Description | |----------|-------------| | err(type, message, additional?) | Create an Err with literal type inference | | errAsync(type, message, additional?) | Async version of err | | ok(value) | Create an Ok (re-export from neverthrow) | | okAsync(value) | Create an async Ok (re-export from neverthrow) | | makeErr(type, message, additional?) | Create error object without wrapping in Err | | rawErr(error) | Direct neverthrow err() for lifting unstructured errors | | isResult(value) | Runtime check if value is a Result | | propagateErr(result) | Propagate error to different Result type |

Types

| Type | Description | |------|-------------| | Result<T, E> | Sync Result (from neverthrow) | | ResultAsync<T, E> | Async Result (from neverthrow) | | ErrorType<Type, Additional?> | Utility for defining { type, message, ...additional } | | ExtractError<T> | Extract error type from Result or Promise | | ExtractFnError<F> | Extract error type from function return type | | ExtractErrors<T[]> | Union of errors from multiple Results | | ExtractFnsError<F[]> | Union of errors from multiple functions |

Requirements

  • TypeScript 5.0+ (for const type parameters)
  • neverthrow 8.x (peer dependency)

License

MIT