From 01de07b0bfd888ac33217e62da47b0d6b24f9f5d Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 13 Jan 2023 17:43:58 -0800 Subject: [PATCH] fix: silence mystery type errors arising from extraction --- packages/captp/src/captp.js | 3 +++ packages/marshal/index.js | 3 +++ packages/marshal/src/encodePassable.js | 3 +++ packages/marshal/src/marshal.js | 6 ++++++ packages/marshal/src/types.js | 10 ++++++++++ packages/pass-style/src/error.js | 6 ++++++ packages/pass-style/src/types.js | 12 +++++++++++- 7 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/captp/src/captp.js b/packages/captp/src/captp.js index c0e57afde7..6b6c7777bd 100644 --- a/packages/captp/src/captp.js +++ b/packages/captp/src/captp.js @@ -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 diff --git a/packages/marshal/index.js b/packages/marshal/index.js index 4f9832eb9f..7d426b729e 100644 --- a/packages/marshal/index.js +++ b/packages/marshal/index.js @@ -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'; diff --git a/packages/marshal/src/encodePassable.js b/packages/marshal/src/encodePassable.js index 40e64fb82c..9d0599cf3a 100644 --- a/packages/marshal/src/encodePassable.js +++ b/packages/marshal/src/encodePassable.js @@ -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: '!', diff --git a/packages/marshal/src/marshal.js b/packages/marshal/src/marshal.js index a5780d9996..a0acaeee2a 100644 --- a/packages/marshal/src/marshal.js +++ b/packages/marshal/src/marshal.js @@ -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, }); diff --git a/packages/marshal/src/types.js b/packages/marshal/src/types.js index ae2af958c9..e79093ce71 100644 --- a/packages/marshal/src/types.js +++ b/packages/marshal/src/types.js @@ -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} CopyArray */ +/** @template T @typedef {import('@endo/pass-style').CopyRecord} CopyRecord */ +/** @typedef {import('@endo/pass-style').InterfaceSpec} InterfaceSpec */ diff --git a/packages/pass-style/src/error.js b/packages/pass-style/src/error.js index 896f677434..2268236c29 100644 --- a/packages/pass-style/src/error.js +++ b/packages/pass-style/src/error.js @@ -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; @@ -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 diff --git a/packages/pass-style/src/types.js b/packages/pass-style/src/types.js index d12e54b235..bee10e201c 100644 --- a/packages/pass-style/src/types.js +++ b/packages/pass-style/src/types.js @@ -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. */ /**