diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..f6f38e2 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,20 @@ +import {Options as FindUpOptions} from 'find-up'; +import {Options as ReadPkgOptions, PackageMetadata} from 'read-pkg'; +export {PackageMetadata} from 'read-pkg'; + +export interface Options extends FindUpOptions, ReadPkgOptions {} + +export interface PackageInfo { + pkg: PackageMetadata; + path: string; +} + +/** Returns a `Promise` for the result object. */ +declare function readPkgUp(options?: Options): Promise; + +declare namespace readPkgUp { + /** Returns the result object. */ + function sync(options?: Options): PackageInfo; +} + +export default readPkgUp; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..42d239c --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,11 @@ +import {expectType} from 'tsd-check'; +import readPkgUp from '.'; +import {PackageMetadata} from '.'; + +(async () => { + expectType(await readPkgUp()); + expectType(await readPkgUp({ cwd: '.', normalize: false })); + + expectType(readPkgUp.sync()); + expectType(readPkgUp.sync({ cwd: '.', normalize: false })); +})(); diff --git a/package.json b/package.json index c8f598e..fc310c8 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": [ "json", @@ -52,6 +53,7 @@ }, "devDependencies": { "ava": "*", + "tsd-check": "^0.2.1", "xo": "*" } }