Skip to content

Commit

Permalink
fix(marshal): Fix typing for TS 4.5 compatibility
Browse files Browse the repository at this point in the history
Make some types explicit any to prevent inference
  • Loading branch information
mhofman committed Feb 3, 2022
1 parent 2ccc8d7 commit 2bbf300
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/eventual-send/src/handled-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export const makeHandledPromise = () => {
},
resolve(value) {
// Resolving a Presence returns the pre-registered handled promise.
let resolvedPromise = presenceToPromise.get(value);
let resolvedPromise = presenceToPromise.get(/** @type {any} */ (value));
if (!resolvedPromise) {
resolvedPromise = Promise.resolve(value);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/marshal/src/dot-membrane.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const { fromEntries } = Object;
const { ownKeys } = Reflect;
const { details: X } = assert;

// TODO(erights): Add Converter type
/** @param {any} [mirrorConverter] */
const makeConverter = (mirrorConverter = undefined) => {
/** @type {WeakMap<any,any>=} */
let mineToYours = new WeakMap();
Expand Down Expand Up @@ -61,6 +63,7 @@ const makeConverter = (mirrorConverter = undefined) => {
break;
}
case 'remotable': {
/** @param {PropertyKey} [optVerb] */
const myMethodToYours = (optVerb = undefined) => (...yourArgs) => {
// We use mineIf rather than mine so that mine is not accessible
// after revocation. This gives the correct error behavior,
Expand Down
4 changes: 3 additions & 1 deletion packages/marshal/src/marshal-justin.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@ const decodeToJustin = (encoding, shouldIndent = false) => {
return out.close(']');
}
} else {
const names = ownKeys(rawTree);
// rawTree is an `EncodingRecord` which only has string keys,
// but since ownKeys is not generic, it can't propagate that
const names = /** @type {string[]} */ (ownKeys(rawTree));
if (names.length === 0) {
return out.next('{}');
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export function makeMarshal(

default: {
assert(
// @ts-expect-error exhaustive check should make condition true
qclass !== 'ibid',
X`The protocol no longer supports ibid encoding: ${rawTree}.`,
);
Expand Down
33 changes: 23 additions & 10 deletions packages/marshal/src/passStyleOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ import './types.js';
import './helpers/internal-types.js';
import { assertPassableSymbol } from './helpers/symbol.js';

/** @typedef {Exclude<PassStyle, PrimitiveStyle | "promise">} HelperPassStyle */

const { details: X, quote: q } = assert;
const { ownKeys } = Reflect;
const { isFrozen } = Object;

/**
* @param {PassStyleHelper[]} passStyleHelpers The passStyleHelpers to register,
* in priority order.
* NOTE These must all be "trusted",
* complete, and non-colliding. `makePassStyleOf` may *assume* that each helper
* does what it is supposed to do. `makePassStyleOf` is not trying to defend
* itself against malicious helpers, though it does defend against some
* accidents.
* @returns {PassStyleOf}
* @param {PassStyleHelper[]} passStyleHelpers
* @returns {Record<HelperPassStyle, PassStyleHelper> }
*/
const makePassStyleOf = passStyleHelpers => {

const makeHelperTable = passStyleHelpers => {
/** @type {Record<HelperPassStyle, any> & {__proto__: null}} */
const HelperTable = {
__proto__: null,
copyArray: undefined,
Expand All @@ -54,7 +52,22 @@ const makePassStyleOf = passStyleHelpers => {
X`missing helper for ${q(styleName)}`,
);
}
harden(HelperTable);

return harden(HelperTable);
};

/**
* @param {PassStyleHelper[]} passStyleHelpers The passStyleHelpers to register,
* in priority order.
* NOTE These must all be "trusted",
* complete, and non-colliding. `makePassStyleOf` may *assume* that each helper
* does what it is supposed to do. `makePassStyleOf` is not trying to defend
* itself against malicious helpers, though it does defend against some
* accidents.
* @returns {PassStyleOf}
*/
const makePassStyleOf = passStyleHelpers => {
const HelperTable = makeHelperTable(passStyleHelpers);
const remotableHelper = HelperTable.remotable;

/**
Expand Down

0 comments on commit 2bbf300

Please sign in to comment.