Skip to content

Commit 9a0b46a

Browse files
committed
Rename keys and entries helpers and update docs
1 parent b8c4966 commit 9a0b46a

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

lib/upload-sarif-action.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload-sarif.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as analyses from "./analyses";
22
import { FeatureEnablement } from "./feature-flags";
33
import { Logger } from "./logging";
44
import * as upload_lib from "./upload-lib";
5-
import { entriesTyped } from "./util";
5+
import { unsafeEntriesInvariant } from "./util";
66

77
// Maps analysis kinds to SARIF IDs.
88
export type UploadSarifResults = Partial<
@@ -33,7 +33,9 @@ export async function uploadSarif(
3333
);
3434

3535
const uploadResults: UploadSarifResults = {};
36-
for (const [analysisKind, sarifFiles] of entriesTyped(sarifGroups)) {
36+
for (const [analysisKind, sarifFiles] of unsafeEntriesInvariant(
37+
sarifGroups,
38+
)) {
3739
const analysisConfig = analyses.getAnalysisConfig(analysisKind);
3840
uploadResults[analysisKind] = await upload_lib.uploadSpecifiedFiles(
3941
sarifFiles,

src/util.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,16 +1288,26 @@ export function isDefined<T>(value: T | null | undefined): value is T {
12881288
return value !== undefined && value !== null;
12891289
}
12901290

1291-
/** Like `Object.keys`, but infers the correct key type. */
1292-
export function keysTyped<T extends Record<string, any>>(
1291+
/** Like `Object.keys`, but typed so that the elements of the resulting array have the
1292+
* same type as the keys of the input object. Note that this may not be sound if the input
1293+
* object has been cast to `T` from a subtype of `T` and contains additional keys that
1294+
* are not represented by `keyof T`.
1295+
*/
1296+
export function unsafeKeysInvariant<T extends Record<string, any>>(
12931297
object: T,
12941298
): Array<keyof T> {
12951299
return Object.keys(object) as Array<keyof T>;
12961300
}
12971301

1298-
/** Like `Object.entries`, but infers the correct key type. */
1299-
export function entriesTyped<T extends Record<string, any>>(
1302+
/** Like `Object.entries`, but typed so that the key elements of the result have the
1303+
* same type as the keys of the input object. Note that this may not be sound if the input
1304+
* object has been cast to `T` from a subtype of `T` and contains additional keys that
1305+
* are not represented by `keyof T`.
1306+
*/
1307+
export function unsafeEntriesInvariant<T extends Record<string, any>>(
13001308
object: T,
1301-
): Array<[keyof T, NonNullable<T[keyof T]>]> {
1302-
return Object.entries(object) as Array<[keyof T, NonNullable<T[keyof T]>]>;
1309+
): Array<[keyof T, Exclude<T[keyof T], undefined>]> {
1310+
return Object.entries(object) as Array<
1311+
[keyof T, Exclude<T[keyof T], undefined>]
1312+
>;
13031313
}

0 commit comments

Comments
 (0)