Skip to content

Commit

Permalink
Add TypeScript definition (#27)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
sebald and sindresorhus committed Mar 2, 2019
1 parent 4d38bea commit b733aa2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
18 changes: 18 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export type Options = Readonly<{
/**
* A preferred port or an array of preferred ports to use.
*/
port?: number | ReadonlyArray<number>,

/**
* The host on which port resolution should be performed. Can be either an IPv4 or IPv6 address.
*/
host?: string;
}>;

/**
* Get an available port number.
*
* @returns Port number.
*/
export default function getPort(options?: Options): Promise<number>;
7 changes: 7 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {expectType} from 'tsd-check';
import getPort from '.';

expectType<number>(await getPort());
expectType<number>(await getPort({port: 3000}));
expectType<number>(await getPort({port: [3000, 3001, 3002]}));
expectType<number>(await getPort({host: 'https://localhost'}));
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"port",
Expand All @@ -38,6 +39,7 @@
"devDependencies": {
"ava": "*",
"pify": "^3.0.0",
"tsd-check": "^0.3.0",
"xo": "*"
}
}

0 comments on commit b733aa2

Please # to comment.