From ce1ee6c93f408e23f1300cb21570e76df37595a2 Mon Sep 17 00:00:00 2001 From: Kyle Farnung Date: Tue, 2 Oct 2018 11:15:27 -0700 Subject: [PATCH] Add typings for `init-package-json` (#29356) --- types/init-package-json/index.d.ts | 26 +++++++++++++++++++ .../init-package-json-tests.ts | 18 +++++++++++++ types/init-package-json/tsconfig.json | 23 ++++++++++++++++ types/init-package-json/tslint.json | 1 + 4 files changed, 68 insertions(+) create mode 100644 types/init-package-json/index.d.ts create mode 100644 types/init-package-json/init-package-json-tests.ts create mode 100644 types/init-package-json/tsconfig.json create mode 100644 types/init-package-json/tslint.json diff --git a/types/init-package-json/index.d.ts b/types/init-package-json/index.d.ts new file mode 100644 index 0000000000..3068846632 --- /dev/null +++ b/types/init-package-json/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for init-package-json 1.10 +// Project: https://github.com/npm/init-package-json#readme +// Definitions by: Kyle Farnung +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace init_package_json { + interface Config { + [key: string]: any; + get(k: string): any; + } + + function yes(conf: Config): boolean; +} + +declare function init_package_json( + dir: string, + input: string, + config: init_package_json.Config | {}, + cb: (err: any, data: any) => void): void; + +declare function init_package_json( + dir: string, + input: string, + cb: (err: any, data: any) => void): void; + +export = init_package_json; diff --git a/types/init-package-json/init-package-json-tests.ts b/types/init-package-json/init-package-json-tests.ts new file mode 100644 index 0000000000..7aecd5f779 --- /dev/null +++ b/types/init-package-json/init-package-json-tests.ts @@ -0,0 +1,18 @@ +import init_package_json = require("init-package-json"); + +init_package_json("", "", (err: any, data: any) => {}); // $ExpectType void +init_package_json("", "", {}, (err: any, data: any) => {}); // $ExpectType void +init_package_json("", "", { foo: "bar" }, (err: any, data: any) => {}); // $ExpectType void + +const config: init_package_json.Config = { + foo: "bar", + get(k) { + return ""; + }, +}; + +init_package_json("", "", config, (err: any, data: any) => {}); // $ExpectType void + +init_package_json.yes({}); // $ExpectError +init_package_json.yes({ foo: "bar" }); // $ExpectError +init_package_json.yes(config); // $ExpectType boolean diff --git a/types/init-package-json/tsconfig.json b/types/init-package-json/tsconfig.json new file mode 100644 index 0000000000..50ed2db1b3 --- /dev/null +++ b/types/init-package-json/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "init-package-json-tests.ts" + ] +} diff --git a/types/init-package-json/tslint.json b/types/init-package-json/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/init-package-json/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }