add normalized package type to read-pkg-up (#22730)

This commit is contained in:
Jeff Dickey
2018-01-07 14:10:23 -08:00
committed by Mohamed Hegazy
parent 7307351dc5
commit 8c3692c2c5
2 changed files with 15 additions and 10 deletions

View File

@@ -1,10 +1,14 @@
// Type definitions for read-pkg-up 2.0
// Type definitions for read-pkg-up 3.0
// Project: https://github.com/sindresorhus/read-pkg-up
// Definitions by: Louis Orleans <https://github.com/dudeofawesome>
// Jeff Dickey <https://github.com/jdxcode>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import normalize = require('normalize-package-data');
declare namespace ReadPkgUp {
function sync(options?: Options): Package;
function sync(options: Options & {normalize: false}): {[k: string]: any};
function sync(options?: Options): normalize.Package;
interface Options {
/**
@@ -21,11 +25,10 @@ declare namespace ReadPkgUp {
normalize?: boolean;
}
interface Package {
[key: string]: any;
}
type Package = normalize.Package;
}
declare function ReadPkgUp(options?: ReadPkgUp.Options): Promise<ReadPkgUp.Package>;
declare function ReadPkgUp(options: ReadPkgUp.Options & {normalize: false}): Promise<{[k: string]: any}>;
declare function ReadPkgUp(options?: ReadPkgUp.Options): Promise<normalize.Package>;
export = ReadPkgUp;

View File

@@ -1,6 +1,8 @@
import ReadPkgUp = require('read-pkg-up');
ReadPkgUp().then(pkg => typeof pkg === 'object');
ReadPkgUp({cwd: '.', normalize: false}).then(pkg => typeof pkg === 'object');
typeof ReadPkgUp.sync() === 'object';
typeof ReadPkgUp.sync({cwd: '.', normalize: false}) === 'object';
ReadPkgUp().then(pkg => pkg.name); // $ExpectType Promise<string>
ReadPkgUp({cwd: '.', normalize: true}).then(pkg => pkg.name); // $ExpectType Promise<string>
ReadPkgUp({cwd: '.', normalize: false}).then(pkg => pkg['name']); // $ExpectType Promise<any>
ReadPkgUp.sync().name; // $ExpectType string
ReadPkgUp.sync({cwd: '.', normalize: true}).name; // $ExpectType string
ReadPkgUp.sync({cwd: '.', normalize: false})['name']; // $ExpectType any