Skip to content

Commit

Permalink
Merge pull request #9 from paulblyth/feat/add-typings
Browse files Browse the repository at this point in the history
Added typings
  • Loading branch information
Aaronius committed Oct 10, 2017
2 parents 0e43a08 + 9736084 commit eaf8ea3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -17,6 +17,7 @@
"promise"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "./scripts/build.js",
"build:watch": "npm run build -- --watch",
Expand Down
2 changes: 2 additions & 0 deletions scripts/build.js
Expand Up @@ -56,6 +56,8 @@ const build = () => {
}
], () => { console.log('Build complete.')});
});

fs.createReadStream('./src/index.d.ts').pipe(fs.createWriteStream('./lib/index.d.ts'));
};

if (argv.watch) {
Expand Down
40 changes: 40 additions & 0 deletions src/index.d.ts
@@ -0,0 +1,40 @@
declare namespace Penpal {

interface IConnectionObject {
promise: Promise<any>;
destroy: () => {};
}

interface IChildConnectionObject extends IConnectionObject {
iframe: HTMLElement;
}

type ConnectionMethods<T> = {
[P in keyof T]: () => Promise<any>;
};

interface IConnectionOptions {
methods?: ConnectionMethods<{}>;
}

interface IChildConnectionOptions extends IConnectionOptions {
appendTo?: HTMLElement;
url: string;
}

interface IParentConnectionOptions extends IConnectionOptions {
parentOrigin?: string[] | string;
}

interface PenpalStatic {
connectToChild(options: IChildConnectionOptions): IChildConnectionObject;
connectToParent(options?: IParentConnectionOptions): IConnectionObject;
Promise: typeof Promise;
debug: Boolean;
}
}

declare module 'penpal' {
const Penpal: Penpal.PenpalStatic;
export = Penpal;
}

0 comments on commit eaf8ea3

Please sign in to comment.