From 5ee6e0fe761da1a13e82d4e0047a995956b467f5 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 15 May 2024 14:56:15 -0700 Subject: [PATCH 1/6] lint: simplify tsconfig --- packages/zoe/tsconfig.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/zoe/tsconfig.json b/packages/zoe/tsconfig.json index e55f61c448a..29af8ccc2dc 100644 --- a/packages/zoe/tsconfig.json +++ b/packages/zoe/tsconfig.json @@ -5,11 +5,11 @@ }, "include": [ "contractFacet.js", - "scripts/**/*.js", + "scripts", + // XXX we need both globs or tsc will ignore the .d.ts twin "src/**/*.js", "src/**/*.ts", - "test/**/*.js", - "test/**/*.ts", - "tools/**/*.js", + "test", + "tools", ], } From a18496027b793fed8f217258e8efca4b9a2bd825 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 14 May 2024 12:32:40 -0700 Subject: [PATCH 2/6] test(types): getPublicFacet --- packages/zoe/src/zoeService/utils.test-d.ts | 2 +- packages/zoe/test/types.test-d.ts | 37 ++++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/zoe/src/zoeService/utils.test-d.ts b/packages/zoe/src/zoeService/utils.test-d.ts index 66eb1d366e6..f92a163e30f 100644 --- a/packages/zoe/src/zoeService/utils.test-d.ts +++ b/packages/zoe/src/zoeService/utils.test-d.ts @@ -3,7 +3,7 @@ import type { StartedInstanceKit } from './utils'; const someContractStartFn = ( zcf: ZCF, privateArgs: { someNumber: number; someString: string }, -) => {}; +) => ({}); type PsmInstanceKit = StartedInstanceKit; diff --git a/packages/zoe/test/types.test-d.ts b/packages/zoe/test/types.test-d.ts index f6f46eee091..420a475226b 100644 --- a/packages/zoe/test/types.test-d.ts +++ b/packages/zoe/test/types.test-d.ts @@ -4,20 +4,22 @@ * because "there is no JavaScript syntax for passing a a type argument" * https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html */ -import { E } from '@endo/eventual-send'; -import { expectType } from 'tsd'; +import { E, RemoteFunctions } from '@endo/eventual-send'; +import { expectNotType, expectType } from 'tsd'; import type { Key } from '@endo/patterns'; // 'prepare' is deprecated but still supported import type { prepare as scaledPriceAuthorityStart } from '../src/contracts/scaledPriceAuthority.js'; +import type { Instance } from '../src/zoeService/utils.js'; +import { PASS_STYLE } from '@endo/marshal'; -{ - const zoe = {} as ZoeService; - const scaledPriceInstallation = {} as Installation< - typeof scaledPriceAuthorityStart - >; +const zoe = {} as ZoeService; +const scaledPriceInstallation = {} as Installation< + typeof scaledPriceAuthorityStart +>; +const mock = null as any; - const mock = null as any; +{ const kit = await E(zoe).startInstance(scaledPriceInstallation); // @ts-expect-error kit.notInKit; @@ -85,3 +87,22 @@ import type { prepare as scaledPriceAuthorityStart } from '../src/contracts/scal const zcfSeat: ZCFSeat = null as any; expectType(zcfSeat); } + +{ + const { instance } = await E(zoe).startInstance(scaledPriceInstallation); + expectType>(instance); + + // XXX remote method requires E() + const pf1 = await zoe.getPublicFacet(instance); + pf1.getPriceAuthority(); + // @ts-expect-error + pf1.notInPublicFacet; + + const rf: RemoteFunctions = mock; + rf.getPublicFacet; + + const pf2 = await E(zoe).getPublicFacet(instance); + pf2.getPriceAuthority(); + // @ts-expect-error + pf2.notInPublicFacet; +} From 2f17f8917c9084930968303c0b832d56bbf8333a Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 13 May 2024 17:07:49 -0700 Subject: [PATCH 3/6] fix(types): Zoe utils hidden by skipLibCheck --- packages/vats/src/core/types-ambient.d.ts | 9 ++++- .../zoe/src/contractFacet/types-ambient.d.ts | 20 ++++++---- packages/zoe/src/zoeService/utils.d.ts | 37 ++++++------------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/vats/src/core/types-ambient.d.ts b/packages/vats/src/core/types-ambient.d.ts index a49cb6be89a..b161f53bf1f 100644 --- a/packages/vats/src/core/types-ambient.d.ts +++ b/packages/vats/src/core/types-ambient.d.ts @@ -251,7 +251,14 @@ type WellKnownSpaces = { }; instance: { produce: Record>; - consume: Record>; + consume: Record> & { + // not worth defining for all contracts. One here just for testing getPublicFacet(instance) + reserve: Promise< + import('@agoric/zoe/src/zoeService/utils.js').Instance< + typeof import('@agoric/inter-protocol/src/reserve/assetReserve.js').start + > + >; + }; }; uiConfig: { produce: Record>>; diff --git a/packages/zoe/src/contractFacet/types-ambient.d.ts b/packages/zoe/src/contractFacet/types-ambient.d.ts index 2dfadbe3be3..81b78ef8f06 100644 --- a/packages/zoe/src/contractFacet/types-ambient.d.ts +++ b/packages/zoe/src/contractFacet/types-ambient.d.ts @@ -1,9 +1,11 @@ -type CopyRecord = import('@endo/pass-style').CopyRecord; -type IssuerOptionsRecord = import('@agoric/ertp').IssuerOptionsRecord; +/// +/// +/// + /** * Any passable non-thenable. Often an explanatory string. */ -type Completion = any; +type Completion = import('@endo/pass-style').Passable; type ZCFMakeEmptySeatKit = (exit?: ExitRule | undefined) => ZcfSeatKit; type InvitationAmount = Amount<'set', InvitationDetails>; @@ -62,7 +64,7 @@ type ZCF> = { proposalShape?: Pattern, ) => Promise>; shutdown: (completion: Completion) => void; - shutdownWithFailure: ShutdownWithFailure; + shutdownWithFailure: import('@agoric/swingset-vat').ShutdownWithFailure; getZoeService: () => ERef; getInvitationIssuer: () => Issuer<'set'>; getTerms: () => StandardTerms & CT; @@ -73,7 +75,7 @@ type ZCF> = { keyword: Keyword, assetKind?: K_2 | undefined, displayInfo?: AdditionalDisplayInfo, - options?: IssuerOptionsRecord, + options?: import('@agoric/ertp').IssuerOptionsRecord, ) => Promise>; registerFeeMint: ZCFRegisterFeeMint; makeEmptySeatKit: ZCFMakeEmptySeatKit; @@ -216,8 +218,8 @@ type OfferHandler = handle: HandleOffer; }; type ContractMeta = { - customTermsShape?: CopyRecord | undefined; - privateArgsShape?: CopyRecord | undefined; + customTermsShape?: import('@endo/pass-style').CopyRecord | undefined; + privateArgsShape?: import('@endo/pass-style').CopyRecord | undefined; upgradability?: 'none' | 'canBeUpgraded' | 'canUpgrade' | undefined; }; /** @@ -238,8 +240,10 @@ type ContractStartFn< type ContractStartFnResult = { publicFacet?: PF; creatorFacet?: CF; - creatorInvitation?: Promise> | undefined; + creatorInvitation?: Promise> | undefined; }; + +// XXX redef, losing documentation type ContractOf = import('../zoeService/utils').ContractOf; type AdminFacet = import('../zoeService/utils').AdminFacet; diff --git a/packages/zoe/src/zoeService/utils.d.ts b/packages/zoe/src/zoeService/utils.d.ts index 2275a21c3ff..0f4f57de889 100644 --- a/packages/zoe/src/zoeService/utils.d.ts +++ b/packages/zoe/src/zoeService/utils.d.ts @@ -8,10 +8,6 @@ import type { RemotableObject } from '@endo/marshal'; // XXX https://github.com/Agoric/agoric-sdk/issues/4565 type SourceBundle = Record; -type ContractFacet = { - readonly [P in keyof T]: T[P] extends Callable ? T[P] : never; -}; - /** * Installation of a contract, typed by its start function. */ @@ -48,41 +44,30 @@ export type AdminFacet = RemotableObject & { : (newPrivateArgs: Parameters[1]) => Promise; }; -type StartParams = SF extends ContractStartFunction +export type StartParams = SF extends ContractStartFunction ? Parameters[1] extends undefined ? { - terms: ReturnType[0]['getTerms']>; + terms: ReturnType['getTerms']>; } : { - terms: ReturnType[0]['getTerms']>; + terms: ReturnType['getTerms']>; privateArgs: Parameters[1]; } : never; -type StartResult = S extends (...args: any) => Promise - ? U - : ReturnType; +type StartResult any> = Awaited>; +type ZcfOf = Parameters[0] extends ZCF + ? Parameters[0] + : ZCF; /** * Convenience record for contract start function, merging its result with params. */ -export type ContractOf = StartParams & StartResult; - -type StartContractInstance = ( - installation: Installation, - issuerKeywordRecord?: Record>, - terms?: object, - privateArgs?: object, -) => Promise<{ - creatorFacet: C['creatorFacet']; - publicFacet: C['publicFacet']; - instance: Instance; - creatorInvitation: C['creatorInvitation']; - adminFacet: AdminFacet; -}>; +export type ContractOf any> = StartParams & + StartResult; /** The result of `startInstance` */ -export type StartedInstanceKit = { +export type StartedInstanceKit = { instance: Instance; adminFacet: AdminFacet; // theses are empty by default. the return type will override @@ -110,6 +95,7 @@ export type StartedInstanceKit = { * the creator facet, public facet, and creator invitation as defined * by the contract. */ +// XXX SF should extend ContractStartFunction but doing that triggers a bunch of tech debt type errors export type StartInstance = ( installation: Installation | PromiseLike>, issuerKeywordRecord?: Record>, @@ -119,6 +105,7 @@ export type StartInstance = ( label?: string, ) => Promise>; +// XXX SF should extend ContractStartFunction but doing that triggers a bunch of tech debt type errors export type GetPublicFacet = ( instance: Instance | PromiseLike>, ) => Promise['publicFacet']>; From 8dd3512a1ad7b6c1c5c247b96f479a4b37b47250 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 13 May 2024 17:13:13 -0700 Subject: [PATCH 4/6] chore(types): misc Zoe cleanup --- packages/zoe/src/contracts/oracle.js | 4 ++++ packages/zoe/src/contracts/priceAggregator.js | 1 + packages/zoe/src/internal-types.js | 3 ++- packages/zoe/src/zoeService/startInstance.js | 2 +- packages/zoe/src/zoeService/utils.d.ts | 5 ++++- packages/zoe/test/types.test-d.ts | 1 - packages/zoe/test/unitTests/blockedOffers.test.js | 4 ++-- .../zoe/test/unitTests/contractSupport/depositTo.test.js | 4 ++-- .../test/unitTests/contractSupport/withdrawFrom.test.js | 4 ++-- packages/zoe/test/unitTests/zcf/zcfSeat-exit.test.js | 7 ++----- packages/zoe/test/unitTests/zoe/burnInvitation.test.js | 2 -- 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/packages/zoe/src/contracts/oracle.js b/packages/zoe/src/contracts/oracle.js index e7efd817506..17f91caa8e1 100644 --- a/packages/zoe/src/contracts/oracle.js +++ b/packages/zoe/src/contracts/oracle.js @@ -6,6 +6,10 @@ import { AmountMath } from '@agoric/ertp'; import { E } from '@endo/eventual-send'; import { atomicTransfer } from '../contractSupport/index.js'; +/** + * @import {ContractOf} from '../zoeService/utils.js'; + */ + /** * This contract provides oracle queries for a fee or for free. * diff --git a/packages/zoe/src/contracts/priceAggregator.js b/packages/zoe/src/contracts/priceAggregator.js index a1be89dc22c..9d0ad6a3904 100644 --- a/packages/zoe/src/contracts/priceAggregator.js +++ b/packages/zoe/src/contracts/priceAggregator.js @@ -32,6 +32,7 @@ import { /** * @import {LegacyMap} from '@agoric/store' + * @import {ContractOf} from '../zoeService/utils.js'; * @import {PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js'; */ /** @typedef {bigint | number | string} ParsableNumber */ diff --git a/packages/zoe/src/internal-types.js b/packages/zoe/src/internal-types.js index b84970e0ffb..59a55eab4df 100644 --- a/packages/zoe/src/internal-types.js +++ b/packages/zoe/src/internal-types.js @@ -1,4 +1,5 @@ // @jessie-check +/// /** * @typedef {object} SeatData @@ -163,7 +164,7 @@ * @param {Keyword} keyword * @param {AssetKind} [assetKind] * @param {AdditionalDisplayInfo} [displayInfo] - * @param {IssuerOptionsRecord} [options] + * @param {import('@agoric/ertp').IssuerOptionsRecord} [options] * @returns {ZoeMint} */ diff --git a/packages/zoe/src/zoeService/startInstance.js b/packages/zoe/src/zoeService/startInstance.js index d18869da130..3219963f3c3 100644 --- a/packages/zoe/src/zoeService/startInstance.js +++ b/packages/zoe/src/zoeService/startInstance.js @@ -66,7 +66,7 @@ export const makeStartInstance = ( adminNode: M.remotable('adminNode'), }); - /** @type {import('@agoric/swingset-liveslots').PromiseWatcher]>} */ + /** @type {import('@agoric/swingset-liveslots').PromiseWatcher]>} */ const watcher = prepareExo( zoeBaggage, 'InstanceCompletionWatcher', diff --git a/packages/zoe/src/zoeService/utils.d.ts b/packages/zoe/src/zoeService/utils.d.ts index 0f4f57de889..a96a44e065e 100644 --- a/packages/zoe/src/zoeService/utils.d.ts +++ b/packages/zoe/src/zoeService/utils.d.ts @@ -1,6 +1,9 @@ +// Ambient types +import '../types-ambient.js'; +import '../contractFacet/types-ambient.js'; + import type { Issuer } from '@agoric/ertp/exported.js'; import type { TagContainer } from '@agoric/internal/src/tagged.js'; -import type { Callable } from '@agoric/internal/src/utils.js'; import type { Baggage } from '@agoric/swingset-liveslots'; import type { VatUpgradeResults } from '@agoric/swingset-vat'; import type { RemotableObject } from '@endo/marshal'; diff --git a/packages/zoe/test/types.test-d.ts b/packages/zoe/test/types.test-d.ts index 420a475226b..533376e739a 100644 --- a/packages/zoe/test/types.test-d.ts +++ b/packages/zoe/test/types.test-d.ts @@ -73,7 +73,6 @@ const mock = null as any; { const zcf = {} as ZCF; - const zoe = {} as ZoeService; const invitation = await zcf.makeInvitation(() => 1n, 'invitation'); expectType>(invitation); const userSeat = E(zoe).offer(invitation); diff --git a/packages/zoe/test/unitTests/blockedOffers.test.js b/packages/zoe/test/unitTests/blockedOffers.test.js index 836f35bbbce..21836df7154 100644 --- a/packages/zoe/test/unitTests/blockedOffers.test.js +++ b/packages/zoe/test/unitTests/blockedOffers.test.js @@ -1,4 +1,3 @@ -// @ts-nocheck import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; import path from 'path'; @@ -22,7 +21,7 @@ const dirname = path.dirname(filename); const contractRoot = `${dirname}/zcf/zcfTesterContract.js`; const setupContract = async (moolaIssuer, bucksIssuer) => { - /** @type {ContractFacet} */ + /** @type {ZCF} */ let zcf; const { admin: fakeVatAdmin, vatAdminState } = makeFakeVatAdmin(jig => { zcf = jig.zcf; @@ -43,6 +42,7 @@ const setupContract = async (moolaIssuer, bucksIssuer) => { await E(zoe).startInstance(installation, issuerKeywordRecord); + // @ts-expect-error may be used before being defined return { zoe, zcf }; }; diff --git a/packages/zoe/test/unitTests/contractSupport/depositTo.test.js b/packages/zoe/test/unitTests/contractSupport/depositTo.test.js index f15349fbac9..ec80e0df791 100644 --- a/packages/zoe/test/unitTests/contractSupport/depositTo.test.js +++ b/packages/zoe/test/unitTests/contractSupport/depositTo.test.js @@ -1,4 +1,3 @@ -// @ts-nocheck import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; import path from 'path'; @@ -18,6 +17,7 @@ const dirname = path.dirname(filename); const contractRoot = `${dirname}/../zcf/zcfTesterContract.js`; async function setupContract(moolaIssuer, bucksIssuer) { + /** @type {any} */ let testJig; const setJig = jig => { testJig = jig; @@ -40,7 +40,7 @@ async function setupContract(moolaIssuer, bucksIssuer) { await E(zoe).startInstance(installation, issuerKeywordRecord); - /** @type {ContractFacet} */ + /** @type {ZCF} */ const zcf = testJig.zcf; return { zoe, zcf }; } diff --git a/packages/zoe/test/unitTests/contractSupport/withdrawFrom.test.js b/packages/zoe/test/unitTests/contractSupport/withdrawFrom.test.js index 14330d6f763..6f8f66e2207 100644 --- a/packages/zoe/test/unitTests/contractSupport/withdrawFrom.test.js +++ b/packages/zoe/test/unitTests/contractSupport/withdrawFrom.test.js @@ -1,4 +1,3 @@ -// @ts-nocheck import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; import path from 'path'; @@ -22,6 +21,7 @@ const dirname = path.dirname(filename); const contractRoot = `${dirname}/../zcf/zcfTesterContract.js`; async function setupContract(moolaIssuer, bucksIssuer) { + /** @type {any} */ let testJig; const setJig = jig => { testJig = jig; @@ -43,7 +43,7 @@ async function setupContract(moolaIssuer, bucksIssuer) { await E(zoe).startInstance(installation, issuerKeywordRecord); - /** @type {ContractFacet} */ + /** @type {ZCF} */ const zcf = testJig.zcf; return { zoe, zcf }; } diff --git a/packages/zoe/test/unitTests/zcf/zcfSeat-exit.test.js b/packages/zoe/test/unitTests/zcf/zcfSeat-exit.test.js index a7ee3b59e88..212ae4becb8 100644 --- a/packages/zoe/test/unitTests/zcf/zcfSeat-exit.test.js +++ b/packages/zoe/test/unitTests/zcf/zcfSeat-exit.test.js @@ -1,4 +1,3 @@ -// @ts-nocheck import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; import path from 'path'; @@ -20,6 +19,7 @@ const contractRoot = `${dirname}/zcfTesterContract.js`; test(`zoe - wrongly throw zcfSeat.exit()`, async t => { const { moolaIssuer, simoleanIssuer } = setup(); + /** @type {any} */ let testJig; const setJig = jig => { testJig = jig; @@ -46,12 +46,11 @@ test(`zoe - wrongly throw zcfSeat.exit()`, async t => { // The contract uses the testJig so the contractFacet // is available here for testing purposes - /** @type {ContractFacet} */ + /** @type {ZCF} */ const zcf = testJig.zcf; /** @type {OfferHandler} */ const throwSeatExit = seat => { - // @ts-expect-error Linting correctly identifies that exit takes no argument. throw seat.exit('here is a string'); }; @@ -67,8 +66,6 @@ test(`zoe - wrongly throw zcfSeat.exit()`, async t => { /** @type {OfferHandler} */ const throwSeatFail = seat => { - // @ts-expect-error Linting correctly identifies that the argument to - // fail must be an error, not a string. throw seat.fail('here is a string'); }; diff --git a/packages/zoe/test/unitTests/zoe/burnInvitation.test.js b/packages/zoe/test/unitTests/zoe/burnInvitation.test.js index 1b5f7c3b1ea..bd4aa29033f 100644 --- a/packages/zoe/test/unitTests/zoe/burnInvitation.test.js +++ b/packages/zoe/test/unitTests/zoe/burnInvitation.test.js @@ -1,5 +1,3 @@ -// @ts-nocheck - import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; import { Far } from '@endo/marshal'; From 20476b89e8cf8ab11efb04062f066c5ae90e9039 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 13 May 2024 17:21:48 -0700 Subject: [PATCH 5/6] chore: update type-coverage --- packages/governance/package.json | 2 +- packages/inter-protocol/package.json | 2 +- packages/zoe/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/governance/package.json b/packages/governance/package.json index 26c0c8d1c0f..453f8fec221 100644 --- a/packages/governance/package.json +++ b/packages/governance/package.json @@ -77,6 +77,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 89.31 + "atLeast": 89.32 } } diff --git a/packages/inter-protocol/package.json b/packages/inter-protocol/package.json index 80a4f529a30..fb0a0077c26 100644 --- a/packages/inter-protocol/package.json +++ b/packages/inter-protocol/package.json @@ -84,6 +84,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 95.86 + "atLeast": 95.87 } } diff --git a/packages/zoe/package.json b/packages/zoe/package.json index 2720037e361..3b9759703e3 100644 --- a/packages/zoe/package.json +++ b/packages/zoe/package.json @@ -140,6 +140,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 84.91 + "atLeast": 84.92 } } From 72b3b763b2f1fdf0c4608d0601a19fd2f3a16709 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 16 May 2024 13:00:01 -0700 Subject: [PATCH 6/6] feat(types): WellKnownSpaces['instance'] --- packages/vats/package.json | 2 +- packages/vats/src/core/types-ambient.d.ts | 54 ++++++++++++---------- packages/vats/test/types-ambient.test-d.ts | 30 ++++++++++++ packages/vats/tsconfig.json | 9 ++-- packages/zoe/test/types.test-d.ts | 2 +- 5 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 packages/vats/test/types-ambient.test-d.ts diff --git a/packages/vats/package.json b/packages/vats/package.json index eaf24a0edba..27a41df47cb 100644 --- a/packages/vats/package.json +++ b/packages/vats/package.json @@ -79,6 +79,6 @@ "workerThreads": false }, "typeCoverage": { - "atLeast": 91.25 + "atLeast": 91.26 } } diff --git a/packages/vats/src/core/types-ambient.d.ts b/packages/vats/src/core/types-ambient.d.ts index b161f53bf1f..5d3daa5bc15 100644 --- a/packages/vats/src/core/types-ambient.d.ts +++ b/packages/vats/src/core/types-ambient.d.ts @@ -201,10 +201,36 @@ type WellKnownName = { uiConfig: 'VaultFactory'; }; -type ContractInstallationPromises = { +type ContractInstallationPromises< + StartFns extends Record, +> = { [Property in keyof StartFns]: Promise>; }; +type ContractInstancePromises< + StartFns extends Record, +> = { + [Property in keyof StartFns]: Promise< + import('@agoric/zoe/src/zoeService/utils.js').Instance + >; +}; + +type WellKnownContracts = { + auctioneer: typeof import('@agoric/inter-protocol/src/auction/auctioneer.js').start; + centralSupply: typeof import('@agoric/vats/src/centralSupply.js').start; + committee: typeof import('@agoric/governance/src/committee.js').start; + contractGovernor: typeof import('@agoric/governance/src/contractGovernor.js').start; + econCommitteeCharter: typeof import('@agoric/inter-protocol/src/econCommitteeCharter.js').start; + feeDistributor: typeof import('@agoric/inter-protocol/src/feeDistributor.js').start; + mintHolder: typeof import('@agoric/vats/src/mintHolder.js').start; + psm: typeof import('@agoric/inter-protocol/src/psm/psm.js').start; + provisionPool: typeof import('@agoric/inter-protocol/src/provisionPool.js').start; + reserve: typeof import('@agoric/inter-protocol/src/reserve/assetReserve.js').start; + VaultFactory: typeof import('@agoric/inter-protocol/src/vaultFactory/vaultFactory.js').start; + // no typeof because walletFactory is exporting `start` as a type + walletFactory: import('@agoric/smart-wallet/src/walletFactory.js').start; +}; + type WellKnownSpaces = { issuer: { produce: Record>; @@ -233,32 +259,12 @@ type WellKnownSpaces = { WellKnownName['installation'], Promise> > & - ContractInstallationPromises<{ - auctioneer: typeof import('@agoric/inter-protocol/src/auction/auctioneer.js').start; - centralSupply: typeof import('@agoric/vats/src/centralSupply.js').start; - committee: typeof import('@agoric/governance/src/committee.js').start; - contractGovernor: typeof import('@agoric/governance/src/contractGovernor.js').start; - econCommitteeCharter: typeof import('@agoric/inter-protocol/src/econCommitteeCharter.js').start; - feeDistributor: typeof import('@agoric/inter-protocol/src/feeDistributor.js').start; - mintHolder: typeof import('@agoric/vats/src/mintHolder.js').start; - psm: typeof import('@agoric/inter-protocol/src/psm/psm.js').start; - provisionPool: typeof import('@agoric/inter-protocol/src/provisionPool.js').start; - reserve: typeof import('@agoric/inter-protocol/src/reserve/assetReserve.js').start; - VaultFactory: typeof import('@agoric/inter-protocol/src/vaultFactory/vaultFactory.js').start; - // no typeof because walletFactory is exporting `start` as a type - walletFactory: import('@agoric/smart-wallet/src/walletFactory.js').start; - }>; + ContractInstallationPromises; }; instance: { produce: Record>; - consume: Record> & { - // not worth defining for all contracts. One here just for testing getPublicFacet(instance) - reserve: Promise< - import('@agoric/zoe/src/zoeService/utils.js').Instance< - typeof import('@agoric/inter-protocol/src/reserve/assetReserve.js').start - > - >; - }; + consume: Record> & + ContractInstancePromises; }; uiConfig: { produce: Record>>; diff --git a/packages/vats/test/types-ambient.test-d.ts b/packages/vats/test/types-ambient.test-d.ts new file mode 100644 index 00000000000..e3264233bc7 --- /dev/null +++ b/packages/vats/test/types-ambient.test-d.ts @@ -0,0 +1,30 @@ +/* eslint-disable @jessie.js/safe-await-separator */ +/* eslint @typescript-eslint/no-floating-promises: "warn" */ +/** + * @file uses .ts syntax to be able to declare types (e.g. of kit.creatorFacet + * as {}) because "there is no JavaScript syntax for passing a a type + * argument" + * https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html + */ + +/// + +import type { start as assetReserveStart } from '@agoric/inter-protocol/src/reserve/assetReserve.js'; +import { expectNotType, expectType } from 'tsd'; + +import type { Instance } from '@agoric/zoe/src/zoeService/utils.js'; + +const mock = null as any; + +const spaces: WellKnownSpaces = mock; + +expectType>( + await spaces.instance.consume.reserve, +); +expectType>( + // @ts-expect-error to check against `any` Instance + await spaces.instance.consume.provisionPool, +); +expectNotType>( + await spaces.instance.consume.provisionPool, +); diff --git a/packages/vats/tsconfig.json b/packages/vats/tsconfig.json index c7434d06f79..53a6a31fd0a 100644 --- a/packages/vats/tsconfig.json +++ b/packages/vats/tsconfig.json @@ -5,10 +5,11 @@ }, "include": [ "*.js", - "scripts/**/*.js", + "scripts", + // XXX we need both globs or tsc will ignore the .d.ts twin "src/**/*.js", - "src/**/*.d.ts", - "test/**/*.js", - "tools/**/*.js", + "src/**/*.ts", + "test", + "tools", ], } diff --git a/packages/zoe/test/types.test-d.ts b/packages/zoe/test/types.test-d.ts index 533376e739a..517f2ae3ee2 100644 --- a/packages/zoe/test/types.test-d.ts +++ b/packages/zoe/test/types.test-d.ts @@ -4,6 +4,7 @@ * because "there is no JavaScript syntax for passing a a type argument" * https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html */ + import { E, RemoteFunctions } from '@endo/eventual-send'; import { expectNotType, expectType } from 'tsd'; @@ -11,7 +12,6 @@ import type { Key } from '@endo/patterns'; // 'prepare' is deprecated but still supported import type { prepare as scaledPriceAuthorityStart } from '../src/contracts/scaledPriceAuthority.js'; import type { Instance } from '../src/zoeService/utils.js'; -import { PASS_STYLE } from '@endo/marshal'; const zoe = {} as ZoeService; const scaledPriceInstallation = {} as Installation<