Monorepo for packages published under the @decorators/*
scope on JSR.
Alias class members to simplify stack traces.
import { alias } from "@decorators/alias";
class Foo {
// alias() can be used to create multiple aliases from one original member
@alias("qux", "nurp")
bar(): string {
return "baz";
}
// declare the aliased members to avoid compilation errors
declare qux: Foo["bar"];
declare nurp: Foo["bar"];
// or, use @alias.for on the alias itself and pass it the original member name.
@alias.for("bar")
baz(): string {
return this.bar();
}
}
const foo = new Foo();
console.assert(foo.bar === "baz"); // OK
console.assert(foo.bar === foo.baz); // OK
console.assert(foo.qux === foo.bar); // OK
console.assert(foo.nurp === foo.bar); // OK
Bind methods, getters, and setters to the appropriate context object, with support for static members and inheritance.
import { bind } from "@decorators/bind";
class Foo {
@bind bar(): Foo {
return this;
}
@bind static self(): typeof Foo {
return this;
}
}
const { self } = Foo, { bar } = new Foo();
console.log(self === Foo); // true
console.log(bar() instanceof Foo); // true