// Implementation exportfunctionmyDecorator<T>(factory: SomeFnType<T>, ...args: any[]): SomeFnType<T> { // extra args means we're being used as a decorator, so run as decorator: if (args.length) returndecorateMethod(myDecorator, factory, ...argsas [any, any]); // No extra args, we're b return () => { } }
Yes, this is fairly ugly, but it's also the only way to make this work
when the wrapper is a generic function. (TypeScript's type system doesn't
allow generic values, declaring functions as implementing interfaces,
higher-order kinds, or any other tricks that would let you avoid this giant
ball of boilerplate for generic decorators.)
Helper for creating hybrid legacy/TC39 decorator/wrapper functions, e.g.:
Yes, this is fairly ugly, but it's also the only way to make this work when the wrapper is a generic function. (TypeScript's type system doesn't allow generic values, declaring functions as implementing interfaces, higher-order kinds, or any other tricks that would let you avoid this giant ball of boilerplate for generic decorators.)