Skip to content

Commit 923a480

Browse files
Merge pull request #3349 from github/robertbrignull/add_types
Add new type parameters to functions where possible
2 parents d7e9606 + cd0d646 commit 923a480

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

extensions/ql-vscode/src/common/jsonl-reader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import { readFile } from "fs-extra";
1010
* @param path The path to the file.
1111
* @param handler Callback to be invoked for each top-level JSON object in order.
1212
*/
13-
export async function readJsonlFile(
13+
export async function readJsonlFile<T>(
1414
path: string,
15-
handler: (value: any) => Promise<void>,
15+
handler: (value: T) => Promise<void>,
1616
): Promise<void> {
1717
const logSummary = await readFile(path, "utf-8");
1818

1919
// Remove newline delimiters because summary is in .jsonl format.
2020
const jsonSummaryObjects: string[] = logSummary.split(/\r?\n\r?\n/g);
2121

2222
for (const obj of jsonSummaryObjects) {
23-
const jsonObj = JSON.parse(obj);
23+
const jsonObj = JSON.parse(obj) as T;
2424
await handler(jsonObj);
2525
}
2626
}

extensions/ql-vscode/src/common/memento.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ export interface Memento {
4040
* @param key A string.
4141
* @param value A value. MUST not contain cyclic references.
4242
*/
43-
update(key: string, value: any): Thenable<void>;
43+
update<T>(key: string, value: T | undefined): Thenable<void>;
4444
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ export function createVSCodeCommandManager<
4040
* @param logger The logger to use for error reporting.
4141
* @param telemetry The telemetry listener to use for error reporting.
4242
*/
43-
export function registerCommandWithErrorHandling(
43+
export function registerCommandWithErrorHandling<
44+
T extends (...args: unknown[]) => Promise<unknown>,
45+
>(
4446
commandId: string,
45-
task: (...args: any[]) => Promise<any>,
47+
task: T,
4648
logger: NotificationLogger = extLogger,
4749
telemetry: AppTelemetry | undefined = telemetryListener,
4850
): Disposable {
49-
return commands.registerCommand(commandId, async (...args: any[]) => {
51+
return commands.registerCommand(commandId, async (...args: Parameters<T>) => {
5052
const startTime = Date.now();
5153
let error: Error | undefined;
5254

extensions/ql-vscode/src/log-insights/log-scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class EvaluationLogScannerSet {
103103
p.createScanner(problemReporter),
104104
);
105105

106-
await readJsonlFile(jsonSummaryLocation, async (obj) => {
106+
await readJsonlFile<SummaryEvent>(jsonSummaryLocation, async (obj) => {
107107
scanners.forEach((scanner) => {
108108
scanner.onEvent(obj);
109109
});

extensions/ql-vscode/src/log-insights/log-summary-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function parseViewerData(
1919
): Promise<EvalLogData[]> {
2020
const viewerData: EvalLogData[] = [];
2121

22-
await readJsonlFile(jsonSummaryPath, async (jsonObj) => {
22+
await readJsonlFile<EvalLogData>(jsonSummaryPath, async (jsonObj) => {
2323
// Only convert log items that have an RA and millis field
2424
if (jsonObj.ra !== undefined && jsonObj.millis !== undefined) {
2525
const newLogData: EvalLogData = {

0 commit comments

Comments
 (0)