Skip to content

Reference

API and configuration reference for typesugar.

Core APIs

ReferenceDescription
MacroContextFull MacroContext API for macro authors
Macro TypesAll 6 macro kinds and their signatures
Macro TriggersHow macros are invoked

Tools

ReferenceDescription
CLICommand-line interface
ConfigurationAll configuration options

Packages

ReferenceDescription
Package MatrixAll packages with features

Registration Functions

typescript
// Expression macro: fn()
defineExpressionMacro(name, { expand(ctx, callExpr) {} });

// Attribute macro: @decorator
defineAttributeMacro(name, { expand(ctx, decorator, target) {} });

// Derive macro: @derive(Name)
defineDeriveMacro(name, { expand(ctx, target, typeInfo) {} });

// Tagged template: tag`...`
defineTaggedTemplateMacro(name, { expand(ctx, node) {} });

// Type macro: Type<T>
defineTypeMacro(name, { expand(ctx, typeRef) {} });

// Labeled block: label: { }
defineLabeledBlockMacro(name, { expand(ctx, block) {} });

Key Imports

typescript
// Core registration
import {
  defineExpressionMacro,
  defineAttributeMacro,
  defineDeriveMacro,
  defineTaggedTemplateMacro,
  defineTypeMacro,
  defineLabeledBlockMacro,
} from "@typesugar/core";

// Quasiquoting
import { quote, quoteStatements, quoteType, ident, raw, spread } from "@typesugar/core/quote";

// Testing
import { expandCode, expandMacro, assertExpands } from "@typesugar/testing";

// Configuration
import { config, cfg, cfgAttr } from "@typesugar/core";

Released under the MIT License.