Skip to content

Commit

Permalink
chore: Make a helper type for restricting object keys to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Mar 5, 2025
1 parent 823efb4 commit 4461c03
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/SwingSet/src/kernel/slogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { q } from '@endo/errors';
import { objectMap } from '@agoric/internal';
import { makeLimitedConsole } from '@agoric/internal/src/ses-utils.js';

/** @import {Callable} from '@agoric/internal'; */
/** @import {Callable, OnlyStringKeys} from '@agoric/internal'; */
/** @import {LimitedConsole} from '@agoric/internal/src/js-utils.js'; */

const IDLE = 'idle';
Expand Down Expand Up @@ -31,7 +31,7 @@ const noopFinisher = harden(() => {});
*/
function addSlogCallbacks(slogCallbacks, unusedMsgPrefix, methods) {
const unused = new Set(Object.keys(slogCallbacks));
const wrappedMethods = /** @type {Methods} */ (
const wrappedMethods = /** @type {OnlyStringKeys<Methods>} */ (
objectMap(methods, (impl, methodKey) => {
const methodName = /** @type {keyof typeof slogCallbacks} */ (methodKey);
unused.delete(methodName);
Expand Down
4 changes: 4 additions & 0 deletions packages/internal/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import type { Primitive } from '@endo/pass-style';
import type { Pattern } from '@endo/patterns';
import type { Callable } from './ses-utils.js';

export type OnlyStringKeys<O> = {
[K in keyof O]: K extends string ? O[K] : never;
};

/**
* A map corresponding with a total function such that `get(key)` is assumed to
* always succeed.
Expand Down

0 comments on commit 4461c03

Please sign in to comment.