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

typesugar

v0.1.0

Published

🧊 TypeScript compile-time macros - Scala 3-style metaprogramming for TypeScript

Readme

typesugar

TypeScript that F*cks! Compile-time macros for TypeScript.

Overview

typesugar brings Scala 3-style metaprogramming to TypeScript. Write macros that transform code at compile time, eliminating runtime overhead while maintaining full type safety.

This is the umbrella package that re-exports all core typesugar functionality. Install this if you want everything.

Installation

npm install typesugar
# or
pnpm add typesugar

Quick Start

1. Configure your bundler

// vite.config.ts
import typesugar from "typesugar/vite";

export default {
  plugins: [typesugar()],
};

2. Use macros in your code

import { comptime, derive, ops, pipe } from "typesugar";

// Compile-time evaluation
const factorial5 = comptime(() => {
  let result = 1;
  for (let i = 1; i <= 5; i++) result *= i;
  return result;
});
// Compiles to: const factorial5 = 120;

// Auto-derived implementations
@derive(Eq, Debug, Clone)
interface User {
  id: number;
  name: string;
}
// Generates: userEq(), debugUser(), cloneUser()

// Operator overloading
@operators({ "+": "add", "*": "scale" })
class Vec2 {
  constructor(public x: number, public y: number) {}
  add(other: Vec2) { return new Vec2(this.x + other.x, this.y + other.y); }
  scale(n: number) { return new Vec2(this.x * n, this.y * n); }
}

const result = ops((v1 + v2) * 3);
// Compiles to: v1.add(v2).scale(3)

// Function composition
const process = pipe(data, parse, validate, transform);
// Compiles to: transform(validate(parse(data)))

Features

Compile-Time Evaluation (@typesugar/comptime)

Evaluate expressions during compilation — constants, computed values, complex logic.

Derive Macros (@typesugar/derive)

Auto-generate implementations: Eq, Ord, Clone, Debug, Hash, Default, Json, Builder, TypeGuard.

Type Reflection (@typesugar/reflect)

Compile-time type introspection: typeInfo<T>(), fieldNames<T>(), validator<T>().

Operator Overloading (@typesugar/operators)

Transform +, -, *, / into method calls on your custom types.

Typeclasses (@typesugar/typeclass)

Scala 3-style typeclass system with @typeclass, @instance, @deriving, and summon().

Zero-Cost Abstractions (@typesugar/specialize)

Eliminate typeclass dictionary passing at compile time for true zero-cost abstractions.

Package Structure

| Package | Description | | ------------------------ | ----------------------------------- | | typesugar | Umbrella package (this one) | | @typesugar/core | Foundation types, registry, context | | @typesugar/transformer | TypeScript transformer | | @typesugar/comptime | Compile-time evaluation | | @typesugar/derive | Derive macros | | @typesugar/reflect | Type reflection | | @typesugar/operators | Operator overloading | | @typesugar/typeclass | Typeclass system | | @typesugar/specialize | Zero-cost specialization | | unplugin-typesugar | Bundler plugins | | @typesugar/vscode | IDE extension |

Bundler Integration

// Vite
import typesugar from "typesugar/vite";

// Webpack
const typesugar = require("typesugar/webpack").default;

// esbuild
import typesugar from "typesugar/esbuild";

// Rollup
import typesugar from "typesugar/rollup";

CLI

# Build with macro expansion
npx typesugar build

# Watch mode
npx typesugar watch

# Type-check only
npx typesugar check

# Show expanded output
npx typesugar expand src/file.ts

API Reference

Re-exported from @typesugar/core

All core types: MacroKind, MacroContext, MacroDefinition, etc.

Re-exported Namespaces

  • comptime — from @typesugar/comptime
  • reflect — from @typesugar/reflect
  • derive — from @typesugar/derive
  • operators — from @typesugar/operators
  • typeclass — from @typesugar/typeclass
  • specialize — from @typesugar/specialize

Functions

  • registerAllMacros() — Register all built-in macros

License

MIT