Skip to content

Commit

Permalink
fixup! better and worse typing
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Feb 20, 2024
1 parent c519ebd commit eeae1bd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 41 deletions.
15 changes: 5 additions & 10 deletions packages/ERTP/src/issuerKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ import { preparePaymentLedger } from './paymentLedger.js';

import './types-ambient.js';

// TODO Why does TypeScript lose the `MapStore` typing of `Baggage` here, even
// though it knows the correct type at the exporting `@agoric/vat-data`
/** @typedef {import('@agoric/vat-data').Baggage} Baggage */
/** @typedef {import('@agoric/zone').Zone} Zone */

/**
* @template {AssetKind} K
* @typedef {object} IssuerRecord
Expand All @@ -30,7 +25,7 @@ import './types-ambient.js';
*
* @template {AssetKind} K
* @param {IssuerRecord<K>} issuerRecord
* @param {Zone} issuerZone
* @param {import('@agoric/zone').Zone} issuerZone
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
* the middle of an atomic action (which btw should never happen), it
* potentially leaves its ledger in a corrupted state. If this function was
Expand Down Expand Up @@ -88,7 +83,7 @@ const INSTANCE_KEY = 'issuer';
* make a new one.
*
* @template {AssetKind} K
* @param {Baggage} issuerBaggage
* @param {import('@agoric/vat-data').Baggage} issuerBaggage
* @param {ShutdownWithFailure} [optShutdownWithFailure] If this issuer fails in
* the middle of an atomic action (which btw should never happen), it
* potentially leaves its ledger in a corrupted state. If this function was
Expand All @@ -111,7 +106,7 @@ harden(upgradeIssuerKit);
/**
* Does baggage already have an issuerKit?
*
* @param {Baggage} baggage
* @param {import('@agoric/vat-data').Baggage} baggage
*/
export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);

Expand Down Expand Up @@ -145,7 +140,7 @@ export const hasIssuer = baggage => baggage.has(INSTANCE_KEY);
* basic fungible tokens.
*
* `displayInfo` gives information to the UI on how to display the amount.
* @param {Baggage} issuerBaggage
* @param {import('@agoric/vat-data').Baggage} issuerBaggage
* @param {string} name
* @param {K} [assetKind]
* @param {AdditionalDisplayInfo} [displayInfo]
Expand Down Expand Up @@ -191,7 +186,7 @@ harden(makeDurableIssuerKit);
* basic fungible tokens.
*
* `displayInfo` gives information to the UI on how to display the amount.
* @param {Baggage} issuerBaggage
* @param {import('@agoric/vat-data').Baggage} issuerBaggage
* @param {string} name
* @param {K} [assetKind]
* @param {AdditionalDisplayInfo} [displayInfo]
Expand Down
4 changes: 2 additions & 2 deletions packages/ERTP/src/mathHelpers/copyBagMathHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
} from '@agoric/store';
import '../types-ambient.js';

/** @type {CopyBag} */
/** @type {import('@endo/patterns').CopyBag} */
const empty = makeCopyBag([]);

/** @type {MathHelpers<CopyBag>} */
/** @type {MathHelpers<import('@endo/patterns').CopyBag>} */
export const copyBagMathHelpers = harden({
doCoerce: bag => {
mustMatch(bag, M.bag(), 'bag of amount');
Expand Down
12 changes: 3 additions & 9 deletions packages/ERTP/src/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

import { initEmpty } from '@agoric/store';

/** @typedef {import('@endo/patterns').MethodGuard} MethodGuard */
/**
* @template {Record<string | symbol, MethodGuard>} [T=Record<string | symbol, MethodGuard>]
* @typedef {import('@endo/patterns').InterfaceGuard<T>} InterfaceGuard
*/
/** @typedef {import('@agoric/zone').Zone} Zone */

// Type InterfaceGuard better than InterfaceGuard<any>
/**
* @template {AssetKind} K
* @param {Zone} issuerZone
* @param {import('@agoric/zone').Zone} issuerZone
* @param {string} name
* @param {Brand<K>} brand
* @param {InterfaceGuard} PaymentI
* @param {import('@endo/patterns').InterfaceGuard<any>} PaymentI
* @returns {() => Payment<K>}
*/
export const preparePaymentKind = (issuerZone, name, brand, PaymentI) => {
Expand Down
4 changes: 1 addition & 3 deletions packages/ERTP/src/paymentLedger.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { preparePurseKind } from './purse.js';
import '@agoric/store/exported.js';
import { BrandI, makeIssuerInterfaces } from './typeGuards.js';

/** @typedef {import('@agoric/zone').Zone} Zone */

const { details: X, quote: q, Fail } = assert;

/**
Expand Down Expand Up @@ -69,7 +67,7 @@ const amountShapeFromElementShape = (brand, assetKind, elementShape) => {
* minting and transfer authority originates here.
*
* @template {AssetKind} K
* @param {Zone} issuerZone
* @param {import('@agoric/zone').Zone} issuerZone
* @param {string} name
* @param {K} assetKind
* @param {DisplayInfo<K>} displayInfo
Expand Down
11 changes: 4 additions & 7 deletions packages/ERTP/src/purse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import { AmountMath } from './amountMath.js';
import { makeTransientNotifierKit } from './transientNotifier.js';
import { makeAmountStore } from './amountStore.js';

// TODO `InterfaceGuard` type parameter
/** @typedef {import('@endo/patterns').InterfaceGuard} InterfaceGuard */
/** @typedef {import('@agoric/zone').Zone} Zone */

const { Fail } = assert;

// Type InterfaceGuard better than InterfaceGuard<any>
/**
* @param {Zone} issuerZone
* @param {import('@agoric/zone').Zone} issuerZone
* @param {string} name
* @param {AssetKind} assetKind
* @param {Brand} brand
* @param {{
* purse: InterfaceGuard;
* depositFacet: InterfaceGuard;
* purse: import('@endo/patterns').InterfaceGuard<any>;
* depositFacet: import('@endo/patterns').InterfaceGuard<any>;
* }} PurseIKit
* @param {{
* depositInternal: any;
Expand Down
13 changes: 4 additions & 9 deletions packages/ERTP/src/types-ambient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

/// <reference types="ses"/>

/**
* @template {Key} [K=Key]
* @typedef {import('@endo/patterns').CopyBag<K>} CopyBag
*/

/**
* @template {AssetKind} [K=AssetKind]
* @typedef {object} Amount Amounts are descriptions of digital assets,
Expand All @@ -22,8 +17,8 @@
*/

/**
* @typedef {NatValue | SetValue | CopySet | CopyBag} AmountValue An
* `AmountValue` describes a set or quantity of assets that can be owned or
* @typedef {NatValue | SetValue | CopySet | import('@endo/patterns').CopyBag} AmountValue
* An `AmountValue` describes a set or quantity of assets that can be owned or
* shared.
*
* A fungible `AmountValue` uses a non-negative bigint to represent a quantity
Expand Down Expand Up @@ -58,7 +53,7 @@
* : K extends 'copySet'
* ? CopySet
* : K extends 'copyBag'
* ? CopyBag
* ? import('@endo/patterns').CopyBag
* : never} AssetValueForKind
*/

Expand All @@ -70,7 +65,7 @@
* ? 'set'
* : V extends CopySet
* ? 'copySet'
* : V extends CopyBag
* : V extends import('@endo/patterns').CopyBag
* ? 'copyBag'
* : never} AssetKindForValue
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('copyBag with strings getValue', t => {
);
t.deepEqual(
getCopyBagEntries(
/** @type {CopyBag} */ (
/** @type {import('@endo/patterns').CopyBag} */ (
m.getValue(
mockBrand,
harden({ brand: mockBrand, value: makeBag(['1']) }),
Expand Down

0 comments on commit eeae1bd

Please sign in to comment.