mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-18 04:24:30 +08:00
Merge pull request #11121 from NoHomey/patch-21
Adding a new type definition for autobind-decorator
This commit is contained in:
43
autobind-decorator/autobind-decorator-tests.ts
Normal file
43
autobind-decorator/autobind-decorator-tests.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/// <reference path="autobind-decorator.d.ts" />
|
||||
|
||||
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'
|
||||
10
autobind-decorator/autobind-decorator.d.ts
vendored
Normal file
10
autobind-decorator/autobind-decorator.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// Type definitions for autobind-decorator v1.3.3
|
||||
// Project: https://github.com/andreypopp/autobind-decorator
|
||||
// Definitions by: Ivo Stratev <https://github.com/NoHomey/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module 'autobind-decorator' {
|
||||
function autobind<TFunction extends Function>(target: TFunction): TFunction | void;
|
||||
function autobind<T extends Function>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;
|
||||
export = autobind;
|
||||
}
|
||||
1
autobind-decorator/autobind-decorator.ts.tscparams
Normal file
1
autobind-decorator/autobind-decorator.ts.tscparams
Normal file
@@ -0,0 +1 @@
|
||||
--experimentalDecorators
|
||||
Reference in New Issue
Block a user