Skip to content

Commit

Permalink
refactor: remove all unnecessary @ts-ignore annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Mar 2, 2021
1 parent 9871903 commit 727706e
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -225,23 +224,26 @@ 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?
);

const endowments = {
...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(','));
Expand Down Expand Up @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ test('install', async t => {
};

const board = makeBoard();
// @ts-ignore
const install = makeInstall(bundleSource, zoe, installationManager, board);

const resolvedPath = resolvePathForPackagedContract(
Expand Down
17 changes: 12 additions & 5 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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);
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions packages/notifier/test/test-subscriber-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion packages/xsnap/lib/lockdown-shim.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore
import 'ses/lockdown';

lockdown();
2 changes: 1 addition & 1 deletion packages/zoe/src/contractFacet/contractFacet.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) {
const issuerTable = makeIssuerTable();
const getAmountMath = brand => issuerTable.getByBrand(brand).amountMath;

/** @type {WeakStore<InvitationHandle, (seat: ZCFSeat) => unknown>} */
const invitationHandleToHandler = makeWeakStore('invitationHandle');

/** @type {Store<ZCFSeat,ZCFSeatAdmin>} */
Expand Down Expand Up @@ -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);
});
Expand Down
5 changes: 3 additions & 2 deletions packages/zoe/src/contracts/autoswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 727706e

Please sign in to comment.