Skip to content

Commit

Permalink
fix: typescript declarations (#189)
Browse files Browse the repository at this point in the history
- add override for string version of function
- fix default export error in Typescript 3.9
  • Loading branch information
sparebytes authored May 26, 2020
1 parent 34689d5 commit 6fee116
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

/**
Sort packageJson.
declare namespace sortPackageJsonExports {
interface SortPackageJsonFn {
/**
* Sort packageJson object.
*
* @param packageJson - A packageJson
* @param options
* @returns Sorted packageJson object
*/
<T extends Record<any, any>>(packageJson: T, options?: Options): T,

/**
* Sort packageJson string.
*
* @param packageJson - A packageJson string.
* @param options
* @returns Sorted packageJson string.
*/
(packageJson: string, options?: Options): string,
}

@param packageJson - A packageJson object or string.
@param options
@returns Sorted packageJson object or string.
*/
declare function sortPackageJsonCore<T extends Record<any, any>>(packageJson: T, options?: sortPackageJsonCore.Options): T;
declare namespace sortPackageJsonCore {
var sortPackageJson: <T extends Record<any, any>>(packageJson: T, options?: sortPackageJsonCore.Options) => T;
// @ts-ignore
var default: <T extends Record<any, any>>(packageJson: T, options?: sortPackageJsonCore.Options) => T;
}
declare namespace sortPackageJsonCore {
type ComparatorFunction = (left: string, right: string) => number;

interface Options {
readonly sortOrder?: readonly string[] | ComparatorFunction;
}
/**
Default sort order.
*/
const sortOrder: readonly string[];
}
export = sortPackageJsonCore;

interface sortPackageJsonExports extends sortPackageJsonExports.SortPackageJsonFn {
readonly default: sortPackageJsonExports.SortPackageJsonFn;
readonly sortPackageJson: sortPackageJsonExports.SortPackageJsonFn;
}

declare const sortPackageJsonExports: sortPackageJsonExports;

export = sortPackageJsonExports;

0 comments on commit 6fee116

Please sign in to comment.