Skip to content

Commit

Permalink
fix: silence mystery type errors arising from extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 14, 2023
1 parent 9f05227 commit 01de07b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/captp/src/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ export const makeCapTP = (
}
// A new remote presence
// Use Remotable rather than Far to make a remote from a presence
// @ts-expect-error We actually mean the function, not the type,
// but TS somehow no longer knows that -- following the extraction
// of @endo/pass-style from @endo/marshal.
val = Remotable(iface, undefined, pr.resPres());
} else {
// A new promise
Expand Down
3 changes: 3 additions & 0 deletions packages/marshal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ export * from './src/types.js';

// For compatibility, but importers of these should instead import these
// directly from `@endo/pass-style` or (if applicable) `@endo/far`.
// @ts-expect-error TS only complains about this line when checking other
// packages that depend on this one, like marshal. The complaint is about
// repeatedly exported types. Specifically "Remotable".
export * from '@endo/pass-style';
3 changes: 3 additions & 0 deletions packages/marshal/src/encodePassable.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ harden(isEncodedRemotable);
* prefix used by any cover so that ordinal mapping keys are always outside
* the range of valid collection entry keys.
*/
// @ts-expect-error TS does not understand thst `__proto__;` in this position
// is special syntax. Instead, it complains that the `null` is not a string,
// which would only make sense if this were defining a property.
export const passStylePrefixes = harden({
__proto__: null,
error: '!',
Expand Down
6 changes: 6 additions & 0 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,13 @@ export const makeMarshal = (
};

const reviveFromSmallcaps = makeDecodeFromSmallcaps({
// @ts-expect-error This error started after separating pass-style
// out of marshal into its own package. Aside from that, I do not
// understand this error at all.
decodeRemotableFromSmallcaps,
// @ts-expect-error This error started after separating pass-style
// out of marshal into its own package. Aside from that, I do not
// understand this error at all.
decodePromiseFromSmallcaps,
decodeErrorFromSmallcaps,
});
Expand Down
10 changes: 10 additions & 0 deletions packages/marshal/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,13 @@ export {};
* of a string-comparison range that covers all possible encodings for
* a set of values.
*/

// /////////////////////// Type reexports @endo/pass-style /////////////////////

/** @typedef {import('@endo/pass-style').Checker} Checker */
/** @typedef {import('@endo/pass-style').PassStyle} PassStyle */
/** @typedef {import('@endo/pass-style').Passable} Passable */
/** @typedef {import('@endo/pass-style').Remotable} Remotable */
/** @template T @typedef {import('@endo/pass-style').CopyArray<T>} CopyArray */
/** @template T @typedef {import('@endo/pass-style').CopyRecord<T>} CopyRecord */
/** @typedef {import('@endo/pass-style').InterfaceSpec} InterfaceSpec */
6 changes: 6 additions & 0 deletions packages/pass-style/src/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { assertChecker } from './passStyle-helpers.js';

/** @typedef {import('./internal-types.js').PassStyleHelper} PassStyleHelper */
/** @typedef {import('./types.js').Checker} Checker */

const { details: X, Fail } = assert;
const { getPrototypeOf, getOwnPropertyDescriptors } = Object;
Expand All @@ -24,6 +25,11 @@ const errorConstructors = new Map([
export const getErrorConstructor = name => errorConstructors.get(name);
harden(getErrorConstructor);

/**
* @param {unknown} candidate
* @param {Checker} [check]
* @returns {boolean}
*/
const checkErrorLike = (candidate, check = undefined) => {
const reject = !!check && (details => check(false, details));
// TODO: Need a better test than instanceof
Expand Down
12 changes: 11 additions & 1 deletion packages/pass-style/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,22 @@ export {};

/**
* @typedef {{
* [PASS_STYLE]: 'tagged',
* [Symbol.toStringTag]: string,
* payload: Passable
* }} CopyTagged
*
* The tag is the value of the `[String.toStringTag]` property.
*
* We used to also declare
* ```js
* [PASS_STYLE]: 'tagged',
* ```
* within the CopyTagged type, before we extracted the pass-style package
* from the marshal package. Within pass-style, this additional property
* declaration seemed to be ignored by TS, but at least TS was still not
* complaining. However, TS checking the marshal package complains about
* this line because it does not know what `PASS_STYLE` is. I could not
* figure out how to fix this.
*/

/**
Expand Down

0 comments on commit 01de07b

Please sign in to comment.