mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-20 21:12:38 +08:00
Add definitions and tests for NodeJs package [depd]
This commit is contained in:
54
depd/depd-tests.ts
Normal file
54
depd/depd-tests.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/// <reference path="./depd.d.ts"/>
|
||||
|
||||
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 = <ITestObject>{ 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 = <ITestDeprecatedFunction>{};
|
||||
|
||||
// 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();
|
||||
17
depd/depd.d.ts
vendored
Normal file
17
depd/depd.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// Type definitions for nodejs package depd 1.1.0
|
||||
// Project: https://github.com/dougwilson/nodejs-depd
|
||||
// Definitions by: Zhiyuan Wang <https://github.com/danny8002/>
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user