From 727706ed5864149968085fca3e59fab8dee41165 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Tue, 16 Feb 2021 12:18:07 -0600 Subject: [PATCH] refactor: remove all unnecessary @ts-ignore annotations --- .../vatManager/supervisor-subprocess-xsnap.js | 19 ++++++++++--------- .../api/test/test-getPursesNotifier.js | 9 +++------ .../test/unitTests/test-install.js | 1 - packages/marshal/src/marshal.js | 17 ++++++++++++----- .../notifier/test/test-subscriber-examples.js | 4 ++-- packages/xsnap/lib/lockdown-shim.js | 1 - .../zoe/src/contractFacet/contractFacet.js | 2 +- packages/zoe/src/contracts/autoswap.js | 5 +++-- .../brokenContracts/crashingAutoRefund.js | 3 +-- 9 files changed, 32 insertions(+), 29 deletions(-) diff --git a/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js b/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js index 87317e5f172..a37e213950c 100644 --- a/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js +++ b/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js @@ -12,7 +12,6 @@ const decoder = new TextDecoder(); // eslint-disable-next-line no-unused-vars function workerLog(first, ...args) { - // @ts-ignore // eslint-disable-next-line // console.log(`---worker: ${first}`, ...args); } @@ -225,13 +224,17 @@ function makeWorker(port) { ]), }; + const cacheSize = + typeof virtualObjectCacheSize === 'number' + ? virtualObjectCacheSize + : undefined; + const ls = makeLiveSlots( syscall, vatID, vatPowers, vatParameters, - // @ts-ignore TODO: defend against non-numeric? - virtualObjectCacheSize, + cacheSize, // TODO: lsgc? API drift? ); @@ -239,9 +242,8 @@ function makeWorker(port) { ...ls.vatGlobals, console: makeConsole(`SwingSet:vatWorker`), assert, - // @ts-ignore bootstrap provides HandledPromise - // eslint-disable-next-line no-undef - HandledPromise, + // bootstrap provides HandledPromise + HandledPromise: globalThis.HandledPromise, }; const vatNS = await importBundle(bundle, { endowments }); workerLog(`got vatNS:`, Object.keys(vatNS).join(',')); @@ -282,8 +284,7 @@ function makeWorker(port) { }); } -// @ts-ignore xsnap provides issueCommand global -// eslint-disable-next-line no-undef -const port = managerPort(issueCommand); +// xsnap provides issueCommand global +const port = managerPort(globalThis.issueCommand); const worker = makeWorker(port); globalThis.handleCommand = port.handlerFrom(worker.handleItem); diff --git a/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js b/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js index c0d76aaf0b3..d7ef14356ee 100644 --- a/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js +++ b/packages/dapp-svelte-wallet/api/test/test-getPursesNotifier.js @@ -86,10 +86,8 @@ test('getAttenuatedPursesNotifier', async t => { // Has the default Zoe invitation purse and a moola purse t.is(update.value.length, 2); const moolaPurseInfo = update.value[1]; - // @ts-ignore - t.is(moolaPurseInfo.actions, undefined); - // @ts-ignore - t.is(moolaPurseInfo.brand, undefined); + t.false('actions' in moolaPurseInfo); + t.false('brand' in moolaPurseInfo); t.is(moolaPurseInfo.brandBoardId, '1532665031'); t.is(moolaPurseInfo.brandPetname, MOOLA_ISSUER_PETNAME); t.deepEqual(moolaPurseInfo.currentAmount, { @@ -110,8 +108,7 @@ test('getAttenuatedPursesNotifier', async t => { amountMathKind: 'nat', }); - // @ts-ignore - t.is(moolaPurseInfo.purse, undefined); + t.false('purse' in moolaPurseInfo); t.is(moolaPurseInfo.pursePetname, MOOLA_PURSE_PETNAME); t.is(moolaPurseInfo.value, 0n); }); diff --git a/packages/deploy-script-support/test/unitTests/test-install.js b/packages/deploy-script-support/test/unitTests/test-install.js index 6be821e74cd..678d9f25518 100644 --- a/packages/deploy-script-support/test/unitTests/test-install.js +++ b/packages/deploy-script-support/test/unitTests/test-install.js @@ -27,7 +27,6 @@ test('install', async t => { }; const board = makeBoard(); - // @ts-ignore const install = makeInstall(bundleSource, zoe, installationManager, board); const resolvedPath = resolvePathForPackagedContract( diff --git a/packages/marshal/src/marshal.js b/packages/marshal/src/marshal.js index 57a85b3b76b..1cb789718c2 100644 --- a/packages/marshal/src/marshal.js +++ b/packages/marshal/src/marshal.js @@ -343,6 +343,15 @@ const makeRemotableProto = (oldProto, allegedName) => { ); }; +/** + * Throw if val is not the correct shape for the prototype of a Remotable. + * + * TODO: It would be nice to typedef this shape and then declare that this + * function asserts it, but we can't declare a type with PASS_STYLE from JSDoc. + * + * @param {{ [PASS_STYLE]: string, [Symbol.toStringTag]: string, toString: () => + * void}} val the value to verify + */ const assertRemotableProto = val => { assert.typeof(val, 'object', X`cannot serialize non-objects like ${val}`); assert(!Array.isArray(val), X`Arrays cannot be pass-by-remote`); @@ -355,11 +364,9 @@ const assertRemotableProto = val => { ); assert(isFrozen(val), X`The Remotable proto must be frozen`); const { - // @ts-ignore [PASS_STYLE]: { value: passStyleValue }, - // @ts-ignore toString: { value: toStringValue }, - // @ts-ignore + // @ts-ignore https://github.com/microsoft/TypeScript/issues/1863 [Symbol.toStringTag]: { value: toStringTagValue }, ...rest } = getOwnPropertyDescriptors(val); @@ -392,8 +399,8 @@ function assertCanBeRemotable(val) { const keys = ownKeys(descs); // enumerable-and-not, string-or-Symbol keys.forEach(key => { assert( - // @ts-ignore - !('get' in descs[key]), + // Typecast needed due to https://github.com/microsoft/TypeScript/issues/1863 + !('get' in descs[/** @type {string} */ (key)]), X`cannot serialize objects with getters like ${q(String(key))} in ${val}`, ); assert.typeof( diff --git a/packages/notifier/test/test-subscriber-examples.js b/packages/notifier/test/test-subscriber-examples.js index e77cf20aaf0..79836a81c03 100644 --- a/packages/notifier/test/test-subscriber-examples.js +++ b/packages/notifier/test/test-subscriber-examples.js @@ -35,9 +35,9 @@ test('subscription for-await-of cannot eat promise', async t => { const { publication, subscription } = makeSubscriptionKit(); paula(publication); const subP = Promise.resolve(subscription); - // @ts-ignore because this test demonstrates the failure that results from + // Type cast because this test demonstrates the failure that results from // giving Alice a promise for a subscription. - const log = await alice(subP); + const log = await alice(/** @type {any} */ (subP)); // This TypeError is thrown by JavaScript when a for-await-in loop // attempts to iterate a promise that is not an async iterable. diff --git a/packages/xsnap/lib/lockdown-shim.js b/packages/xsnap/lib/lockdown-shim.js index 25d481feac8..a67d383cbeb 100644 --- a/packages/xsnap/lib/lockdown-shim.js +++ b/packages/xsnap/lib/lockdown-shim.js @@ -1,4 +1,3 @@ -// @ts-ignore import 'ses/lockdown'; lockdown(); diff --git a/packages/zoe/src/contractFacet/contractFacet.js b/packages/zoe/src/contractFacet/contractFacet.js index 1cdd832f04c..d125bd447bc 100644 --- a/packages/zoe/src/contractFacet/contractFacet.js +++ b/packages/zoe/src/contractFacet/contractFacet.js @@ -43,6 +43,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { const issuerTable = makeIssuerTable(); const getAmountMath = brand => issuerTable.getByBrand(brand).amountMath; + /** @type {WeakStore unknown>} */ const invitationHandleToHandler = makeWeakStore('invitationHandle'); /** @type {Store} */ @@ -441,7 +442,6 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { zcfSeatToZCFSeatAdmin.init(zcfSeat, zcfSeatAdmin); zcfSeatToSeatHandle.init(zcfSeat, seatHandle); const offerHandler = invitationHandleToHandler.get(invitationHandle); - // @ts-ignore const offerResultP = E(offerHandler)(zcfSeat).catch(reason => { throw zcfSeat.fail(reason); }); diff --git a/packages/zoe/src/contracts/autoswap.js b/packages/zoe/src/contracts/autoswap.js index ba3cb317829..6b4d42a23eb 100644 --- a/packages/zoe/src/contracts/autoswap.js +++ b/packages/zoe/src/contracts/autoswap.js @@ -83,8 +83,9 @@ const start = async zcf => { */ const getPoolKeyword = brand => { assert(brandToKeyword.has(brand), 'getPoolKeyword: brand not found'); - // @ts-ignore - return brandToKeyword.get(brand); + const keyword = brandToKeyword.get(brand); + assert.typeof(keyword, 'string'); + return keyword; }; const { zcfSeat: poolSeat } = zcf.makeEmptySeatKit(); diff --git a/packages/zoe/test/swingsetTests/brokenContracts/crashingAutoRefund.js b/packages/zoe/test/swingsetTests/brokenContracts/crashingAutoRefund.js index d501689a00e..7b164e4804a 100644 --- a/packages/zoe/test/swingsetTests/brokenContracts/crashingAutoRefund.js +++ b/packages/zoe/test/swingsetTests/brokenContracts/crashingAutoRefund.js @@ -25,8 +25,7 @@ const start = zcf => { if (terms.throw) { throw new Error('blowup in makeContract'); } else if (terms.meter) { - // @ts-ignore - return new Array(1e9); + return { publicFacet: new Array(1e9) }; } const safeAutoRefund = seat => {