Skip to content

Commit

Permalink
Add deprecated decorator
Browse files Browse the repository at this point in the history
For internal use
  • Loading branch information
zajrik committed Apr 15, 2017
1 parent 02c1e3e commit ef7cf41
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/util/DeprecatedDecorator.ts
Original file line number Diff line number Diff line change
@@ -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<T extends Function>(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;
};
}

0 comments on commit ef7cf41

Please sign in to comment.