A decorator is a function that returns a series of "hooks":
function dec() {
return [
{ register(klass) { } },
{ register(target, key) { } },
{ wrap(f) { return f; } },
{ initialize(target, key, value) { } },
{ expose(target, key, get, set) { } },
];
}
A "hook" is an object with one or more "hook methods" and an optional for
filter:
type DecoratorHook =
| { register(klass: Function): void, for?: "class" }
| { register(target: object, key: string | symbol): void, for?: "method" }
| { wrap(f: Function): Function, for?: "class" | "method" }
| { initialize(instance: object, key: string | symbol, value: unknown): void, for?: "field" }
| { expose(
target: object,
key: string | symbol,
get: (instance: object) => unknown,
set: (instance: object, value: unknown) => void
): void,
for?: "method" | "field"
};