Skip to content

Feature Guides

Deep-dive guides for typesugar features, organized by category.

Standard Library

Everyday features from @typesugar/std:

GuideDescription
Extension MethodsUFCS, @opaque dot syntax, global augmentation
Pattern MatchingExhaustive match() with discriminated unions
Pattern Matching (v2)Scala-style structural patterns, exhaustiveness, extractors
Do-NotationMonadic let:/yield: and applicative par:/yield:
Standard TypeclassesEq, Ord, Hash, Show, Monoid, FlatMap

Typeclasses & Derivation

The framework for ad-hoc polymorphism:

GuideDescription
TypeclassesScala 3-style implicit resolution
Derive MacrosAuto-generate implementations with @derive()
SpecializationZero-cost typeclass inlining
ReflectiontypeInfo<T>(), fieldNames<T>(), validator<T>()

Syntax Sugar

New language features — the "typesugar" in typesugar:

GuideDescription
OperatorsOperator overloading via @op JSDoc on typeclass methods
Tagged TemplatesType-safe SQL, regex, HTML, and units
String Macrosregex, html, raw templates
Compile-Time EvalRun code at build time with comptime()
Conditional CompilationFeature flags with cfg() and @cfgAttr

Type Safety & Contracts

Compile-time correctness guarantees:

GuideDescription
ContractsDesign by contract with requires:/ensures:
Refined TypesIntegration with refinement types
Type SystemRefined types, newtype, HKT, phantom types
ValidationSchema validation macros
Units of MeasureType-safe physical units

Data Structures & Algorithms

Powerful abstractions with zero runtime cost:

GuideDescription
Functional ProgrammingOption, Either, IO with @opaque dot syntax
HListHeterogeneous lists (Boost.Fusion)
Type Erasuredyn Trait for heterogeneous collections
Loop FusionSingle-pass iterator pipelines
Parser CombinatorsPEG grammar to parser (Boost.Spirit)
CollectionsTypeclasses for collections, HashSet, HashMap
Graph AlgorithmsGraphLike typeclass, BFS, DFS, Dijkstra, state machines
Versioned CodecsSchema evolution (serde)
MathRational, complex, matrix, interval
Object MappingZero-cost struct transformation
Symbolic MathCalculus, simplification, rendering

Ecosystem Integrations

Supercharge your existing tools:

GuideDescription
Effect-TS@service, @layer, resolveLayer<R>()
SQLDoobie-like type-safe SQL

Developer Experience

When something goes wrong, you should know exactly what happened and how to get the level of type safety you want:

GuideDescription
Type SafetyThe three-layer model: build, IDE, CI
OverviewHow error messages, suggestions, and tooling work
Error MessagesRust-style errors with labeled spans
Opt-Out DirectivesDisable transformations for debugging
TestingPower assertions, property testing
Library ManifestPublishing typesugar-powered libraries
Interactive PlaygroundTry code in-browser with runtime libraries, 20+ examples

Quick Reference

Import Patterns

typescript
// Standard library
import { clamp, abs, match, registerFlatMap } from "@typesugar/std";

// Derive macros
import { derive, Eq, Ord, Clone, Debug, Json } from "@typesugar/derive";

// Typeclasses
import { typeclass, instance, derive, summon } from "@typesugar/typeclass";

// Operators (pipe, compose)
import { pipe, compose } from "typesugar";

// Compile-time
import { comptime, includeStr, staticAssert } from "@typesugar/macros";

// Contracts
import { requires, ensures, invariant } from "@typesugar/contracts";

// FP
import { Option, Some, None, Result, Ok, Err, IO } from "@typesugar/fp";

// SQL
import { sql, ConnectionIO } from "@typesugar/sql";

// Testing
import { assert, staticAssert, typeAssert, forAll } from "@typesugar/testing";

Feature Matrix

FeaturePackageMacro Type
comptime()@typesugar/macrosExpression
@derive()@typesugar/deriveAttribute
@typeclass@typesugar/typeclassAttribute
summon<T>()@typesugar/typeclassExpression
match()@typesugar/stdExpression
sql@typesugar/sqlTagged Template
requires:@typesugar/contractsLabeled Block
let:/yield:@typesugar/stdLabeled Block
par:/yield:@typesugar/stdLabeled Block
cfg()@typesugar/coreExpression
assert()@typesugar/testingExpression

Released under the MIT License.