diff --git a/src/util/DeprecatedDecorator.ts b/src/util/DeprecatedDecorator.ts new file mode 100644 index 00000000..a5a6a3ec --- /dev/null +++ b/src/util/DeprecatedDecorator.ts @@ -0,0 +1,22 @@ +import { Logger } from './logger/Logger'; +const logger: Logger = Logger.instance(); + +/** + * Logs a deprecation warning for the decorated class method + * @private + * @param {string} [message] Method deprecation message + */ +export function deprecated(message?: string): MethodDecorator +{ + return function(target: T, key: string, descriptor: PropertyDescriptor): PropertyDescriptor + { + if (!descriptor) descriptor = Object.getOwnPropertyDescriptor(target, key); + const original: any = descriptor.value; + descriptor.value = function(...args: any[]): any + { + logger.warn('Deprecation', message || `${target.constructor.name}#${key}() is deprecated and will be removed in a future release.`); + return original.apply(this, args); + }; + return descriptor; + }; +}