Merge pull request #3349 from github/robertbrignull/add_types
Add new type parameters to functions where possible
This commit is contained in:
@@ -10,9 +10,9 @@ import { readFile } from "fs-extra";
|
||||
* @param path The path to the file.
|
||||
* @param handler Callback to be invoked for each top-level JSON object in order.
|
||||
*/
|
||||
export async function readJsonlFile(
|
||||
export async function readJsonlFile<T>(
|
||||
path: string,
|
||||
handler: (value: any) => Promise<void>,
|
||||
handler: (value: T) => Promise<void>,
|
||||
): Promise<void> {
|
||||
const logSummary = await readFile(path, "utf-8");
|
||||
|
||||
@@ -20,7 +20,7 @@ export async function readJsonlFile(
|
||||
const jsonSummaryObjects: string[] = logSummary.split(/\r?\n\r?\n/g);
|
||||
|
||||
for (const obj of jsonSummaryObjects) {
|
||||
const jsonObj = JSON.parse(obj);
|
||||
const jsonObj = JSON.parse(obj) as T;
|
||||
await handler(jsonObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,5 +40,5 @@ export interface Memento {
|
||||
* @param key A string.
|
||||
* @param value A value. MUST not contain cyclic references.
|
||||
*/
|
||||
update(key: string, value: any): Thenable<void>;
|
||||
update<T>(key: string, value: T | undefined): Thenable<void>;
|
||||
}
|
||||
|
||||
@@ -40,13 +40,15 @@ export function createVSCodeCommandManager<
|
||||
* @param logger The logger to use for error reporting.
|
||||
* @param telemetry The telemetry listener to use for error reporting.
|
||||
*/
|
||||
export function registerCommandWithErrorHandling(
|
||||
export function registerCommandWithErrorHandling<
|
||||
T extends (...args: unknown[]) => Promise<unknown>,
|
||||
>(
|
||||
commandId: string,
|
||||
task: (...args: any[]) => Promise<any>,
|
||||
task: T,
|
||||
logger: NotificationLogger = extLogger,
|
||||
telemetry: AppTelemetry | undefined = telemetryListener,
|
||||
): Disposable {
|
||||
return commands.registerCommand(commandId, async (...args: any[]) => {
|
||||
return commands.registerCommand(commandId, async (...args: Parameters<T>) => {
|
||||
const startTime = Date.now();
|
||||
let error: Error | undefined;
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ export class EvaluationLogScannerSet {
|
||||
p.createScanner(problemReporter),
|
||||
);
|
||||
|
||||
await readJsonlFile(jsonSummaryLocation, async (obj) => {
|
||||
await readJsonlFile<SummaryEvent>(jsonSummaryLocation, async (obj) => {
|
||||
scanners.forEach((scanner) => {
|
||||
scanner.onEvent(obj);
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ export async function parseViewerData(
|
||||
): Promise<EvalLogData[]> {
|
||||
const viewerData: EvalLogData[] = [];
|
||||
|
||||
await readJsonlFile(jsonSummaryPath, async (jsonObj) => {
|
||||
await readJsonlFile<EvalLogData>(jsonSummaryPath, async (jsonObj) => {
|
||||
// Only convert log items that have an RA and millis field
|
||||
if (jsonObj.ra !== undefined && jsonObj.millis !== undefined) {
|
||||
const newLogData: EvalLogData = {
|
||||
|
||||
Reference in New Issue
Block a user