Skip to content

Commit

Permalink
chore(internal): Define TotalMap<K, V> and TotalMapFrom<Map<K, V>> types
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Jul 31, 2024
1 parent d7844ae commit ef7c3a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
15 changes: 1 addition & 14 deletions packages/internal/src/storage-test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,12 @@ import { bindAllMethods } from './method-tools.js';
import { eventLoopIteration } from './testing-utils.js';

/**
* @import {TotalMap} from './types.js';
* @import {Marshaller, StorageEntry, StorageMessage, StorageNode} from './lib-chainStorage.js';
*/

const trace = makeTracer('StorTU', false);

/**
* A map corresponding with a total function such that `get(key)` is assumed to
* always succeed.
*
* @template K, V
* @typedef {{ [k in Exclude<keyof Map<K, V>, 'get'>]: Map<K, V>[k] } & {
* get: (key: K) => V;
* }} TotalMap
*/
/**
* @template T
* @typedef {T extends Map<infer K, infer V> ? TotalMap<K, V> : never} TotalMapFrom
*/

/**
* A convertSlotToVal function that produces basic Remotables. Assumes that all
* slots are Remotables (i.e. none are Promises).
Expand Down
12 changes: 12 additions & 0 deletions packages/internal/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import type { ERef, RemotableBrand } from '@endo/eventual-send';
import type { Primitive } from '@endo/pass-style';
import type { Callable } from './utils.js';

/**
* A map corresponding with a total function such that `get(key)` is assumed to
* always succeed.
*/
export type TotalMap<K, V> = {
[k in Exclude<keyof Map<K, V>, 'get'>]: Map<K, V>[k];
} & {
get: (key: K) => V;
};
export type TotalMapFrom<M> =
M extends Map<infer K, infer V> ? TotalMap<K, V> : never;

export declare class Callback<I extends (...args: unknown[]) => any> {
private iface: I;

Expand Down

0 comments on commit ef7c3a3

Please sign in to comment.