Improve type of trapCaches now Language is non-exhaustive

This commit is contained in:
Henry Mercer
2025-08-05 18:09:37 +01:00
parent ea05bf27b6
commit 377976a96e
10 changed files with 13 additions and 19 deletions
+1 -4
View File
@@ -99,10 +99,7 @@ async function sendStatusReport(
...report,
trap_cache_upload_duration_ms: Math.round(trapCacheUploadTime || 0),
trap_cache_upload_size_bytes: Math.round(
await getTotalCacheSize(
Object.values(config.trapCaches).filter((x) => x !== undefined),
logger,
),
await getTotalCacheSize(Object.values(config.trapCaches), logger),
),
};
await statusReport.sendStatusReport(trapCacheUploadStatusReport);
+3 -3
View File
@@ -146,7 +146,7 @@ export interface Config {
* Partial map from languages to locations of TRAP caches for that language.
* If a key is omitted, then TRAP caching should not be used for that language.
*/
trapCaches: Partial<Record<Language, string>>;
trapCaches: { [language: Language]: string };
/**
* Time taken to download TRAP caches. Used for status reporting.
@@ -537,10 +537,10 @@ async function downloadCacheWithTime(
languages: Language[],
logger: Logger,
): Promise<{
trapCaches: Partial<Record<Language, string>>;
trapCaches: { [language: string]: string };
trapCacheDownloadTime: number;
}> {
let trapCaches = {};
let trapCaches: { [language: string]: string } = {};
let trapCacheDownloadTime = 0;
if (trapCachingEnabled) {
const start = performance.now();
+1 -4
View File
@@ -240,10 +240,7 @@ async function sendCompletedStatusReport(
packs: JSON.stringify(packs),
trap_cache_languages: Object.keys(config.trapCaches).join(","),
trap_cache_download_size_bytes: Math.round(
await getTotalCacheSize(
Object.values(config.trapCaches).filter((x) => x !== undefined),
logger,
),
await getTotalCacheSize(Object.values(config.trapCaches), logger),
),
trap_cache_download_duration_ms: Math.round(config.trapCacheDownloadTime),
overlay_base_database_download_size_bytes:
+2 -2
View File
@@ -50,8 +50,8 @@ export async function downloadTrapCaches(
codeql: CodeQL,
languages: Language[],
logger: Logger,
): Promise<Partial<Record<Language, string>>> {
const result: Partial<Record<Language, string>> = {};
): Promise<{ [language: string]: string }> {
const result: { [language: string]: string } = {};
const languagesSupportingCaching = await getLanguagesSupportingCaching(
codeql,
languages,