Merge pull request #19233 from sculove/egjs-component-types

add typings for egjs-component
This commit is contained in:
Bowden Kelly
2017-08-23 17:02:36 -07:00
committed by GitHub
4 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import * as Component from "@egjs/component";
class TestKlass extends Component {
}
let is = false;
const klass = new TestKlass();
klass.options;
is = klass.hasOn("click");
klass.on("click", () => {
});
klass.on({
click1: () => {
},
click2: e => {
}
});
klass.once("click", () => {
});
klass.once({
click1: () => {
},
click2: e => {
}
});
klass.off("click", () => {
});
klass.off("click");
klass.off();
is = klass.trigger("click");
is = klass.trigger("click", {
test: 1
});

30
types/egjs__component/index.d.ts vendored Normal file
View File

@@ -0,0 +1,30 @@
// Type definitions for egjs-component 2.0
// Project: https://github.com/naver/egjs-component
// Definitions by: Naver <https://github.com/naver>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
export as namespace eg;
export = Component;
declare class Component {
constructor(options?: { [key: string]: any });
trigger(eventName: string, customEvent?: { [key: string]: any }): boolean;
hasOn(eventName: string): boolean;
on(eventName: string, handlerToAttach: (event: { [key: string]: any }) => any): Component;
on(events: { [key: string]: (event: { [key: string]: any }) => any }): Component;
off(eventName?: string, handlerToAttach?: (event: { [key: string]: any }) => any): Component;
once(events: { [key: string]: (event: { [key: string]: any }) => any }): Component;
once(eventName: string, handlerToAttach: (event: { [key: string]: any }) => any): Component;
options: { [key: string]: any };
}
declare namespace Component {
function trigger(eventName: string, customEvent?: { [key: string]: any }): boolean;
function hasOn(eventName: string): boolean;
function on(eventName: string, handlerToAttach: (event: { [key: string]: any }) => any): Component;
function on(events: { [key: string]: (event: { [key: string]: any }) => any }): Component;
function off(eventName?: string, handlerToAttach?: (event: { [key: string]: any }) => any): Component;
function once(events: { [key: string]: (event: { [key: string]: any }) => any }): Component;
function once(eventName: string, handlerToAttach: (event: { [key: string]: any }) => any): Component;
let options: { [key: string]: any };
}

View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths":{
"@egjs/component": ["egjs__component"]
}
},
"files": [
"index.d.ts",
"egjs__component-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }