Skip to content

Quick Start

Install

bash
npm install @litert/decorator

Configure TypeScript

Modern decorators require TypeScript's standard decorator transform. Disable experimentalDecorators and include this package's metadata typings:

json
{
    "compilerOptions": {
        "experimentalDecorators": false,
        "types": ["@litert/decorator"]
    }
}

Legacy decorators require TypeScript's old experimental decorator transform:

json
{
    "compilerOptions": {
        "experimentalDecorators": true
    }
}

Modern decorator

ts
import {
    Methods,
    getMetadataContainer,
} from '@litert/decorator';

function mark(name: string): Methods.ICallbackFn {

    return Methods.withArgsCheck((_method, ctx) => {
        ctx.metadata![name] = true;
    });
}

class Service {

    @mark('tracked')
    public run(): void {}
}

console.log(getMetadataContainer(Service).get('tracked'));

Legacy decorator

ts
import 'reflect-metadata';
import { Methods } from '@litert/decorator/legacy';

function mark(name: string): Methods.ICallbackFn {

    return Methods.create((ctx) => {
        Reflect.defineMetadata(name, ctx.name, ctx.constructor);
    });
}

class Service {

    @mark('tracked')
    public run(): void {}
}

console.log(Reflect.getMetadata('tracked', Service));

Note: Legacy decorators use reflect-metadata for metadata storage. Do not use getMetadataContainer — it is designed for modern (Stage 3) decorators only.

Compatible decorator

ts
import 'reflect-metadata';
import { Methods } from '@litert/decorator/compatible';

const mark = Methods.create({
    legacy: (ctx) => {
        Reflect.defineMetadata('tracked', ctx.name, ctx.constructor);
    },
    modern: (_method, ctx) => {
        ctx.metadata!['tracked'] = ctx.name;
    },
});

Choose an entrypoint

SituationImport path
New TypeScript standard decorators@litert/decorator
Explicit modern import path@litert/decorator/modern
Existing experimentalDecorators code@litert/decorator/legacy
Shared decorators used by both builds@litert/decorator/compatible

Next steps

PagePurpose
TutorialsLearn the common decorator construction patterns.
FAQReview mode-specific behavior and migration questions.
API OverviewBrowse the full public API.