diff --git a/autobind-decorator/autobind-decorator-tests.ts b/autobind-decorator/autobind-decorator-tests.ts new file mode 100644 index 0000000000..e428604802 --- /dev/null +++ b/autobind-decorator/autobind-decorator-tests.ts @@ -0,0 +1,43 @@ +/// + +import autobind = require('autobind-decorator'); + +class Test { + public static what: string = 'static'; + + @autobind + public static test(): void { + console.log(this.what); + } + + public constructor(public what: string) { + this.what = what; + } + + @autobind + public test(): void { + console.warn(this.what); + } +} + +const tester: Test = new Test('bind'); +const { test } = tester; +tester.test(); // warns 'bind'. +test(); // warns 'bind'. +Test.test(); // logs 'static'. + +@autobind +class Component { + public constructor(private someMember: string) { + this.someMember = someMember; + } + + public someMethod(): void { + console.error(this.someMember); + } +} + +const component: Component = new Component('React vs Angular2'); +const { someMethod } = component; +component.someMethod(); // errors 'React vs Angular2' +someMethod(); // errors 'React vs Angular2' diff --git a/autobind-decorator/autobind-decorator.d.ts b/autobind-decorator/autobind-decorator.d.ts new file mode 100644 index 0000000000..51ba89c9bf --- /dev/null +++ b/autobind-decorator/autobind-decorator.d.ts @@ -0,0 +1,10 @@ +// Type definitions for autobind-decorator v1.3.3 +// Project: https://github.com/andreypopp/autobind-decorator +// Definitions by: Ivo Stratev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'autobind-decorator' { + function autobind(target: TFunction): TFunction | void; + function autobind(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void; + export = autobind; +} diff --git a/autobind-decorator/autobind-decorator.ts.tscparams b/autobind-decorator/autobind-decorator.ts.tscparams new file mode 100644 index 0000000000..1ee3d05cb6 --- /dev/null +++ b/autobind-decorator/autobind-decorator.ts.tscparams @@ -0,0 +1 @@ +--experimentalDecorators