From ee5dffce66ae102783f3c23cfc836696110fdf62 Mon Sep 17 00:00:00 2001 From: Zhiyuan Wang Date: Fri, 30 Oct 2015 08:28:47 +0800 Subject: [PATCH] Add definitions and tests for NodeJs package [depd] --- depd/depd-tests.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++ depd/depd.d.ts | 17 +++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 depd/depd-tests.ts create mode 100644 depd/depd.d.ts diff --git a/depd/depd-tests.ts b/depd/depd-tests.ts new file mode 100644 index 0000000000..14dfbe72c4 --- /dev/null +++ b/depd/depd-tests.ts @@ -0,0 +1,54 @@ +/// + +import depd = require('depd'); + +var deprecate = depd("depd-tests"); + +function assert(condition: boolean, message: string): void { + if (!condition) { + throw new Error(message); + } +} + +function testDepdMessage(...args: string[]): boolean { + if (arguments.length < 1) { + deprecate('testDepdMessage argument.lenth<1'); + return true; + } else { + console.log('normal logic'); + return false; + } +} + +assert(testDepdMessage() === true, "Deprecated code must be triggered!"); +assert(testDepdMessage('a') === false, "Deprecated code must be triggered!"); + +interface ITestObject { + p1: string; + p2: string; +} + +var obj = { p1: 'deprecated property', p2: 'normal property' }; +deprecate.property(obj, 'p1', 'property [p1] is deprecated!'); + +console.log(obj.p1); + +interface ITestDeprecatedFunction { + func1?: Function; + func2?: Function; +} + +var obj2 = {}; + +// message automatically derived from function name +obj2.func1 = deprecate.function(function func1() { + console.log('all calls to [func1] are deprecated '); +}); + +// specific message +obj2.func2 = deprecate.function(function () { + console.log('all calls to [func2] are deprecated '); +}, 'func2'); + +obj2.func1(); +obj2.func2(); \ No newline at end of file diff --git a/depd/depd.d.ts b/depd/depd.d.ts new file mode 100644 index 0000000000..33f7b72a04 --- /dev/null +++ b/depd/depd.d.ts @@ -0,0 +1,17 @@ +// Type definitions for nodejs package depd 1.1.0 +// Project: https://github.com/dougwilson/nodejs-depd +// Definitions by: Zhiyuan Wang +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module 'depd' { + function depd(namespace: string): Deprecate; + + interface Deprecate { + (message: string): void; + function(fn: Function, message?: string): Function; + property(obj: Object, prop: string, message: string): void; + } + + export = depd; +} \ No newline at end of file