Skip to content

Commit

Permalink
fix: expose all three inspect() overloads in plugin types (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Yegupov authored Jul 23, 2019
1 parent 0411f4b commit 6d75118
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,25 @@ export interface GradleInspectOptions {

type Options = InspectOptions & GradleInspectOptions;

// TODO: move everything to inspect.ts, and make index.ts just a re-export of `inspect` with a typecheck
// Overload type definitions, so that when you call inspect() with an `options` literal (e.g. in tests),
// you will get a result of a specific corresponding type.
export async function inspect(
root: string,
targetFile: string,
options?: SingleSubprojectInspectOptions & GradleInspectOptions):
Promise<SinglePackageResult>;
options?: SingleSubprojectInspectOptions & GradleInspectOptions,
): Promise<SinglePackageResult>;
export async function inspect(
root: string,
targetFile: string,
options: MultiSubprojectInspectOptions & GradleInspectOptions):
Promise<MultiProjectResult>;
options: MultiSubprojectInspectOptions & GradleInspectOptions,
): Promise<MultiProjectResult>;

// General implementation. The result type depends on the runtime type of `options`.
export async function inspect(
root: string,
targetFile: string,
options?: Options,
): Promise<InspectResult> {
root: string,
targetFile: string,
options?: Options,
): Promise<InspectResult> {
if (!options) {
options = {dev: false};
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"author": "snyk.io",
"license": "Apache-2.0",
"devDependencies": {
"@snyk/cli-interface": "^1.2.0",
"@snyk/cli-interface": "^1.3.1",
"@types/chalk": "^2.2.0",
"@types/jest": "^24.0.13",
"@types/node": "^4.9.1",
Expand Down

0 comments on commit 6d75118

Please sign in to comment.