From b733aa2bb456d51b9210a3190979b5b60a4be5a8 Mon Sep 17 00:00:00 2001 From: Sebastian Sebald Date: Sat, 2 Mar 2019 20:03:01 +0100 Subject: [PATCH] Add TypeScript definition (#27) Co-authored-by: Sindre Sorhus --- index.d.ts | 18 ++++++++++++++++++ index.test-d.ts | 7 +++++++ package.json | 6 ++++-- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 index.d.ts create mode 100644 index.test-d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..40b8afc --- /dev/null +++ b/index.d.ts @@ -0,0 +1,18 @@ +export type Options = Readonly<{ + /** + * A preferred port or an array of preferred ports to use. + */ + port?: number | ReadonlyArray, + + /** + * 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; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..eca3d91 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,7 @@ +import {expectType} from 'tsd-check'; +import getPort from '.'; + +expectType(await getPort()); +expectType(await getPort({port: 3000})); +expectType(await getPort({port: [3000, 3001, 3002]})); +expectType(await getPort({host: 'https://localhost'})); diff --git a/package.json b/package.json index 71726fa..e51b511 100644 --- a/package.json +++ b/package.json @@ -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", @@ -38,6 +39,7 @@ "devDependencies": { "ava": "*", "pify": "^3.0.0", + "tsd-check": "^0.3.0", "xo": "*" } }