Skip to content

Commit d6bd482

Browse files
Merge pull request #3330 from github/robertbrignull/debug_configuration_makearray
Remove use of any and make typing clearer in debugger code
2 parents 39cbe3b + db5293a commit d6bd482

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

extensions/ql-vscode/src/common/helpers-pure.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77

88
import { RedactableError } from "./errors";
99

10+
// Matches any type that is not an array. This is useful to help avoid
11+
// nested arrays, or for cases like createSingleSelectionCommand to avoid T
12+
// accidentally getting instantiated as DatabaseItem[] instead of DatabaseItem.
13+
export type NotArray =
14+
| string
15+
| bigint
16+
| number
17+
| boolean
18+
| (object & {
19+
length?: never;
20+
});
21+
1022
/**
1123
* This error is used to indicate a runtime failure of an exhaustivity check enforced at compile time.
1224
*/

extensions/ql-vscode/src/common/vscode/selection-commands.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ import type {
33
TreeViewContextMultiSelectionCommandFunction,
44
TreeViewContextSingleSelectionCommandFunction,
55
} from "../commands";
6+
import type { NotArray } from "../helpers-pure";
67
import type { NotificationLogger } from "../logging";
78
import { showAndLogErrorMessage } from "../logging";
89

9-
// A hack to match types that are not an array, which is useful to help avoid
10-
// misusing createSingleSelectionCommand, e.g. where T accidentally gets instantiated
11-
// as DatabaseItem[] instead of DatabaseItem.
12-
type NotArray = object & { length?: never };
13-
1410
// A way to get the type system to help assert that one type is a supertype of another.
1511
type CreateSupertypeOf<Super, Sub extends Super> = Sub;
1612

extensions/ql-vscode/src/debugger/debug-configuration.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
88
import type { LocalQueries } from "../local-queries";
99
import { getQuickEvalContext, validateQueryPath } from "../run-queries-shared";
1010
import type { LaunchConfig } from "./debug-protocol";
11+
import type { NotArray } from "../common/helpers-pure";
1112
import { getErrorMessage } from "../common/helpers-pure";
1213
import { showAndLogErrorMessage } from "../common/logging";
1314
import { extLogger } from "../common/logging/vscode";
@@ -22,7 +23,7 @@ export interface QLDebugArgs {
2223
extensionPacks?: string[] | string;
2324
quickEval?: boolean;
2425
noDebug?: boolean;
25-
additionalRunQueryArgs?: Record<string, any>;
26+
additionalRunQueryArgs?: Record<string, unknown>;
2627
}
2728

2829
/**
@@ -39,7 +40,7 @@ export type QLDebugConfiguration = DebugConfiguration & QLDebugArgs;
3940
export type QLResolvedDebugConfiguration = DebugConfiguration & LaunchConfig;
4041

4142
/** If the specified value is a single element, then turn it into an array containing that element. */
42-
function makeArray<T extends Exclude<any, any[]>>(value: T | T[]): T[] {
43+
function makeArray<T extends NotArray>(value: T | T[]): T[] {
4344
if (Array.isArray(value)) {
4445
return value;
4546
} else {

extensions/ql-vscode/src/debugger/debug-protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export interface LaunchConfig {
7171
/** Run the query without debugging it. */
7272
noDebug: boolean;
7373
/** Undocumented: Additional arguments to be passed to the `runQuery` API on the query server. */
74-
additionalRunQueryArgs: Record<string, any>;
74+
additionalRunQueryArgs: Record<string, unknown>;
7575
}
7676

7777
export interface LaunchRequest extends Request, DebugProtocol.LaunchRequest {

0 commit comments

Comments
 (0)