diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 7885adcf4..1470a5824 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -88590,7 +88590,7 @@ async function asyncSome(array, predicate) { const results = await Promise.all(array.map(predicate)); return results.some((result) => result); } -function entriesTyped(object) { +function unsafeEntriesInvariant(object) { return Object.entries(object); } @@ -93485,7 +93485,9 @@ async function uploadSarif(logger, features, checkoutPath, sarifPath, category) sarifPath ); const uploadResults = {}; - for (const [analysisKind, sarifFiles] of entriesTyped(sarifGroups)) { + for (const [analysisKind, sarifFiles] of unsafeEntriesInvariant( + sarifGroups + )) { const analysisConfig = getAnalysisConfig(analysisKind); uploadResults[analysisKind] = await uploadSpecifiedFiles( sarifFiles, diff --git a/src/upload-sarif.ts b/src/upload-sarif.ts index f16c7fb21..34b912489 100644 --- a/src/upload-sarif.ts +++ b/src/upload-sarif.ts @@ -2,7 +2,7 @@ import * as analyses from "./analyses"; import { FeatureEnablement } from "./feature-flags"; import { Logger } from "./logging"; import * as upload_lib from "./upload-lib"; -import { entriesTyped } from "./util"; +import { unsafeEntriesInvariant } from "./util"; // Maps analysis kinds to SARIF IDs. export type UploadSarifResults = Partial< @@ -33,7 +33,9 @@ export async function uploadSarif( ); const uploadResults: UploadSarifResults = {}; - for (const [analysisKind, sarifFiles] of entriesTyped(sarifGroups)) { + for (const [analysisKind, sarifFiles] of unsafeEntriesInvariant( + sarifGroups, + )) { const analysisConfig = analyses.getAnalysisConfig(analysisKind); uploadResults[analysisKind] = await upload_lib.uploadSpecifiedFiles( sarifFiles, diff --git a/src/util.ts b/src/util.ts index 94475ce62..1fb193798 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1288,16 +1288,26 @@ export function isDefined(value: T | null | undefined): value is T { return value !== undefined && value !== null; } -/** Like `Object.keys`, but infers the correct key type. */ -export function keysTyped>( +/** Like `Object.keys`, but typed so that the elements of the resulting array have the + * same type as the keys of the input object. Note that this may not be sound if the input + * object has been cast to `T` from a subtype of `T` and contains additional keys that + * are not represented by `keyof T`. + */ +export function unsafeKeysInvariant>( object: T, ): Array { return Object.keys(object) as Array; } -/** Like `Object.entries`, but infers the correct key type. */ -export function entriesTyped>( +/** Like `Object.entries`, but typed so that the key elements of the result have the + * same type as the keys of the input object. Note that this may not be sound if the input + * object has been cast to `T` from a subtype of `T` and contains additional keys that + * are not represented by `keyof T`. + */ +export function unsafeEntriesInvariant>( object: T, -): Array<[keyof T, NonNullable]> { - return Object.entries(object) as Array<[keyof T, NonNullable]>; +): Array<[keyof T, Exclude]> { + return Object.entries(object) as Array< + [keyof T, Exclude] + >; }