Typespun
Reference

Decorators and annotations

The six markers Typespun reads at build time — Config, Default, Env, Key, Secret and Ignore — in both their JSDoc form for interfaces and their inert decorator form for classes.

Decorators are imported from typespun. They return inert decorator functions; the code generator reads their meaning statically and the runtime does not store metadata.

Class decoratorInterface JSDocSignatureMeaning
Config()@typespunConfig(): (...args: readonly unknown[]) => undefinedMarks the one exported root.
Default(value)@default <JSON>Default(value: unknown): (...args: readonly unknown[]) => undefinedSupplies an inline default.
Env(name)@env NAMEEnv(name: string): (...args: readonly unknown[]) => undefinedReplaces a leaf's complete environment name.
Key(name)@key nameKey(name: string): (...args: readonly unknown[]) => undefinedReplaces one JSON/YAML defaults path segment.
Secret()@secretSecret(): (...args: readonly unknown[]) => undefinedRedacts Typespun diagnostics for a leaf or branch.
Ignore()@ignoreIgnore(): (...args: readonly unknown[]) => undefinedExcludes a property or branch.
src/config.ts
import { Config, Default, Env, Ignore, Key, Secret } from 'typespun';

@Config()
export class AppConfig {
  @Default(3000)
  port!: number;

  @Env('DATABASE_URL')
  @Key('database_url')
  @Secret()
  databaseUrl!: string;

  @Ignore()
  label = 'not configuration';
}

Decorator arguments must be statically supported literals. Env and Key require one string. Environment names must match [A-Za-z_][A-Za-z0-9_]*. Keys must be one nonempty safe segment without a dot.

JSDoc @default accepts JSON text. Class defaults accept strings, finite numbers, booleans, supported arrays and object literals, negative numeric literals, or string enum members. Expressions and user modules are not executed. A class field initializer acts as a default unless @Default supplies one. Defaults must match the declared leaf type.

@Env applies only to leaves. @Secret on an object applies to every included descendant. @Key affects compiled defaults only; environment names still come from TypeScript property paths unless @Env is present.

JSDoc annotations are also accepted on class declarations and fields, although the decorator form is the intended class style. TypeScript decorators cannot be applied to interfaces.