Package Reference
All typesugar packages organized by category.
Build Infrastructure
typesugar
Umbrella package including all common packages.
npm install typesugarIncludes: core, derive, reflect, typeclass, specialize.
Inspired by: Umbrella packages (Lodash, Effect)
@typesugar/core
Macro registration and types.
npm install @typesugar/coreExports:
// Registration
defineExpressionMacro;
defineAttributeMacro;
defineDeriveMacro;
defineTaggedTemplateMacro;
defineTypeMacro;
defineLabeledBlockMacro;
// Types
MacroContext;
MacroDefinition;
DeriveTypeInfo;
ComptimeValue;
// Configuration
config;
cfg;
cfgAttr;
// Diagnostics
DiagnosticBuilder;
DiagnosticDescriptor;
renderDiagnosticCLI;
// Resolution Scope
globalResolutionScope;
isInOptedOutScope;
hasInlineOptOut;
// Import Suggestions
getSuggestionsForSymbol;
getSuggestionsForMethod;@typesugar/macros
Built-in macro implementations. Internal package — most users should import from typesugar or specific feature packages.
npm install @typesugar/macrosExports:
// Typeclass System
typeclassRegistry;
instanceRegistry;
// Derive Infrastructure
defineCustomDerive;
defineFieldDerive;
extractTypeInfo;
// Extension Methods
extensionAttribute; // @extension decorator
// "use extension" directive (file-level)
// And many more internal implementations...Inspired by: Rust macro system, Scala 3 metaprogramming
@typesugar/transformer
The TypeScript transformer that expands macros.
npm install --save-dev @typesugar/transformerExports:
- Default export: transformer factory
- CLI:
typesugarcommand
@typesugar/preprocessor
Lexical preprocessor for HKT type syntax (F<A> → Kind<F, A>) plus the shared source-map types used by the transformer pipeline.
npm install --save-dev @typesugar/preprocessorExports:
preprocess();Inspired by: Zig comptime
unplugin-typesugar
Bundler plugins for Vite, Webpack, esbuild, Rollup.
npm install --save-dev unplugin-typesugarExports:
import typesugar from "unplugin-typesugar/vite";
import typesugar from "unplugin-typesugar/webpack";
import typesugar from "unplugin-typesugar/esbuild";
import typesugar from "unplugin-typesugar/rollup";@typesugar/ts-plugin
TypeScript language service plugin for IDE integration.
npm install --save-dev @typesugar/ts-pluginEnables type-aware transformation, diagnostics, go-to-definition, completions, and hover info for typesugar syntax in any TypeScript editor.
Developer Experience
@typesugar/vscode
VSCode/Cursor extension (install from marketplace).
- Syntax highlighting for custom syntax
- Inline expansion previews
- Go-to-definition for macro-generated code
- Error lens integration
@typesugar/eslint-plugin
ESLint plugin with processor for typesugar files.
npm install --save-dev @typesugar/eslint-pluginExports:
configs.recommended;
configs.full;
configs.strict;
processor;@typesugar/prettier-plugin
Prettier formatting for custom syntax.
npm install --save-dev @typesugar/prettier-plugin@typesugar/testing
Power assertions, property-based testing, macro testing.
npm install --save-dev @typesugar/testingExports:
assert(); // Power assertion with sub-expression capture
staticAssert(); // Compile-time assertion
typeAssert<T>(); // Type-level assertion
testCases(); // Parameterized tests
forAll(); // Property-based testing
assertSnapshot(); // Source-capturing snapshotsInspired by: Power Assert (JS), QuickCheck (Haskell), proptest (Rust)
Standard Library
@typesugar/std
Standard library extensions: typeclasses, extension methods, pattern matching, do-notation.
npm install @typesugar/stdExports:
// Extension methods (import functions, call as methods)
(abs, ceil, floor, sqrt, clamp, isEven, isPrime); // number
(capitalize, titleCase, strip, truncate); // string
(head, tail, chunk, unique, groupBy); // array
// Pattern matching — fluent API (PEP-008)
match(); // Fluent: match(v).case(...).then(...).else(...)
MatchError; // Runtime error when no pattern matches (extends Error, has .value)
// FlatMap for do-notation
FlatMap;
registerFlatMap();
// Standard typeclasses
(Eq, Ord, Show, Hash, Semigroup, Monoid);
// Hash instances and combinators
(hashNumber, hashString, hashBoolean, hashBigInt, hashDate);
(makeHash, hashBy, hashArray);Inspired by: Scala 3 extension methods, Rust derives, Kotlin stdlib
Extension Methods Guide · Pattern Matching Guide · Do-Notation Guide · Standard Typeclasses Guide
Typeclasses & Derivation
@typesugar/typeclass
Scala 3-style typeclasses with implicit resolution.
npm install @typesugar/typeclassExports:
typeclass(); // decorator
instance(); // decorator
derive(); // decorator (generates typeclass instances)
summon<T>();
summonAll<...>();
extend();
implicit(); // default parameter markerInspired by: Scala 3 typeclasses, Haskell typeclasses
@typesugar/derive
Auto-derive implementations from type structure.
npm install @typesugar/deriveExports:
derive(); // decorator
(Eq, Ord, Clone, Debug, Hash, Default, Json, Builder, TypeGuard);
(deriveIgnore, deriveWith);Inspired by: Rust derive macros
@typesugar/specialize
Zero-cost typeclass specialization.
npm install @typesugar/specializeExports:
specialize();
specialize$();
mono<T>();
inlineCall();Inspired by: GHC SPECIALIZE pragma, Rust monomorphization
@typesugar/reflect
Compile-time type reflection.
npm install @typesugar/reflectExports:
reflect(); // decorator
typeInfo<T>();
fieldNames<T>();
validator<T>();Inspired by: Zig @typeInfo, Rust proc_macro
Syntax Sugar
@typesugar/strings
String validation macros with compile-time checking.
npm install @typesugar/stringsExports:
regex`...`; // tagged template
html`...`; // tagged template
raw`...`; // tagged template
fmt`...`; // tagged templateType Safety & Contracts
@typesugar/type-system
Advanced type system extensions.
npm install @typesugar/type-systemExports:
// HKT
($, Kind, _, TypeFunction, ArrayF, PromiseF);
// Newtype
(Newtype, wrap, unwrap, newtypeCtor);
// Refinement
(Refined, refine);
(Positive, NonNegative, Int, Byte, Port);
(NonEmpty, Email, Url, Uuid);
// Vec
Vec;
// Type-level arithmetic
(Add, Sub, Mul, Div, Pow);Inspired by: Haskell/ML type systems, Scala 3 opaque types
@typesugar/contracts
Design by contract with compile-time verification.
npm install @typesugar/contractsExports:
requires:; // labeled block
ensures:; // labeled block
invariant(); // decorator
old();
assert();
configure();Inspired by: Eiffel contracts, Coq proofs
@typesugar/contracts-refined
Refinement type integration for contracts.
npm install @typesugar/contracts-refinedExports:
registerRefinementPredicate();
getRegisteredPredicates();@typesugar/validate
Zero-cost validation and schema macros.
npm install @typesugar/validateExports:
is<T>(); // type guard
assert<T>(); // assertion
validate<T>(); // validation with error accumulation
Schema; // schema DSLInspired by: Zod, io-ts
@typesugar/units
Type-safe physical units with dimensional analysis.
npm install @typesugar/unitsExports:
// Unit class with .add(), .sub(), .mul(), .div(), .to(), .scale(), .equals()
Unit;
// Constructors
(meters, kilometers, centimeters, millimeters, feet, inches, miles);
(kilograms, grams, milligrams, pounds);
(seconds, minutes, hours, days, milliseconds);
(metersPerSecond, kilometersPerHour, milesPerHour);
(newtons, joules, kilojoules, watts, kilowatts);
(kelvin, celsius, pascals, kilopascals, atmospheres);
units`...`; // tagged template
// Dimension types
(Length, Mass, Time, Velocity, Force, Energy, Power, Pressure, Temperature);
(MulDimensions, DivDimensions, SameDimensions);Inspired by: Boost.Units, F# Units of Measure
Data Structures & Algorithms
@typesugar/fp
Functional programming data types.
npm install @typesugar/fpExports:
// Option (null-based, zero-cost)
(Option, Some, None);
// Result
(Result, Ok, Err);
// Either
(Either, Left, Right);
// Validated
(Validated, Valid, Invalid);
// IO
IO;
// List
(List, Cons, Nil);
// Typeclasses
(Functor, Applicative, Monad);
(Semigroup, Monoid);
(Eq, Ord, Show);Inspired by: Scala fp-ts, Haskell Prelude
@typesugar/hlist
Heterogeneous lists with compile-time type tracking.
npm install @typesugar/hlistExports:
hlist();
(head(), tail(), last(), at());
(append(), prepend(), concat(), reverse(), zip());
(labeled(), get(), set(), project(), merge());
(map(), foldLeft(), forEach());Inspired by: Boost.Fusion, Boost.Hana
@typesugar/fusion
Single-pass iterator fusion and expression templates.
npm install @typesugar/fusionExports:
lazy();
(range(), iterate(), repeat(), generate());
(vec(), add(), sub(), mul(), dot());Inspired by: Blitz++, Rust iterators
@typesugar/parser
Compile-time parser generation from PEG grammars.
npm install @typesugar/parserExports:
grammar`...`; // tagged template
(literal(), char(), charRange(), regex());
(seq(), alt(), many(), many1(), optional());
(map(), sepBy(), between(), lazy());Inspired by: Boost.Spirit, PEG.js
@typesugar/graph
Graph algorithms and state machine verification.
npm install @typesugar/graphExports:
(createDigraph(), createGraph());
digraph`...`; // tagged template
(topoSort(), bfs(), dfs(), dijkstra());
(stronglyConnectedComponents(), detectCycles());
(defineStateMachine(), verify());
// GraphLike typeclass
(GraphLike, WeightedGraphLike);
(graphLike, weightedGraphLike);
// Generic algorithms (parameterized over GraphLike + Eq + Hash)
(topoSortG, hasCyclesG, bfsG, dfsG, reachableG, hasPathG, shortestPathG, dijkstraWithG, sccG);Inspired by: Boost.Graph
@typesugar/erased
Typeclass-based type erasure for heterogeneous collections.
npm install @typesugar/erasedExports:
eraseWith();
(showable(), equatable(), showableEq());
(show(), equals(), compare(), hash(), clone());
(widen(), narrow(), hasCapability());Inspired by: Rust dyn Trait
@typesugar/codec
Versioned codecs with schema evolution.
npm install @typesugar/codecExports:
schema();
createJsonCodec();
createBinaryCodec();
generateMigrations();Inspired by: serde, Boost.Serialization, Protocol Buffers
@typesugar/collections
Collection typeclasses and hash-based data structures.
npm install @typesugar/collectionsExports:
// Typeclasses
(IterableOnce, Iterable, Seq, SetLike, MapLike);
(PersistentSetLike, PersistentMapLike, MutableSetLike, MutableMapLike);
// Data structures
(HashSet, HashMap);
// Instances
(arrayIterableOnce, arrayIterable, arraySeq, arraySeqOf);
(nativeSetLike, nativeMutableSetLike, nativeMapLike, nativeMutableMapLike);
(stringIterable, stringSeq);
(hashSetLike, hashMutableSetLike, hashMapLike, hashMutableMapLike);
(mutableSetFor, mutableMapFor);
// Derived operations
(forEach, toArray, find, exists, forAll, count, sum);
(head, last, take, drop, sorted, seqContains);
(union, intersection, difference, isSubsetOf);
(getOrElse, mapValues, filterEntries, mapEntries);Inspired by: Scala collections, Haskell Data.Set/Data.Map, Rust std::collections
@typesugar/math
Math types and typeclasses.
npm install @typesugar/mathExports:
(rational(), complex(), bigDecimal());
(matrix(), det(), matMul(), transpose());
(interval(), mod(), polynomial());
(VectorSpace, InnerProduct, Normed);Inspired by: Haskell Numeric, Boost.Multiprecision
@typesugar/mapper
Zero-cost object mapping.
npm install @typesugar/mapperExports:
transformInto<S, T>();Inspired by: Scala Chimney
@typesugar/symbolic
Type-safe symbolic mathematics with AST, rendering, evaluation, calculus, and simplification.
npm install @typesugar/symbolicExports:
// AST construction
var_;
const_;
add;
mul;
pow;
sin;
cos;
ln;
// Calculus
diff;
integrate;
limit;
// Evaluation & rendering
evaluate;
toLatex;
toMathML;
simplify;
solve;Inspired by: SymPy, Mathematica
Ecosystem Integrations
@typesugar/effect
Effect-TS integration.
npm install @typesugar/effect effectExports:
// Service & Layer (primary)
service(); // decorator
layer(); // decorator
layerMake<R>(); // ZIO-style explicit wiring
resolveLayer<R>(); // implicit wiring from import scope
formatDebugTree(); // resolved graph visualization
// Derives
(EffectSchema, EffectEqual, EffectHash);
// Extensions
(EffectExt, OptionExt, EitherExt);
// Typeclass instances
(effectFunctor, effectMonad);Inspired by: Scala ZIO
@typesugar/sql
Type-safe SQL tagged templates with ConnectionIO.
npm install @typesugar/sqlExports:
sql`...`; // tagged template
(Query, Update, Fragment);
ConnectionIO;
Transactor;Inspired by: Scala Doobie
Peer Dependencies
Most packages have:
typescript: >=5.0.0@typesugar/transformer: >=0.1.0(peer)
Check each package's package.json for specifics.
