Skip to content

Commit db5293a

Browse files
Convert makeArray to use NotArray
1 parent e93ef98 commit db5293a

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
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: 2 additions & 1 deletion
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";
@@ -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<unknown, unknown[]>>(value: T | T[]): T[] {
43+
function makeArray<T extends NotArray>(value: T | T[]): T[] {
4344
if (Array.isArray(value)) {
4445
return value;
4546
} else {

0 commit comments

Comments
 (0)