From 0c98c96627d514bb5aebf34d2c63a8e1561b9204 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 9 Feb 2024 20:14:52 -0800 Subject: [PATCH] fixup! review suggestions --- packages/pass-style/src/error.js | 40 +++++++++++++------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/packages/pass-style/src/error.js b/packages/pass-style/src/error.js index 1bbeed3004..9171d43991 100644 --- a/packages/pass-style/src/error.js +++ b/packages/pass-style/src/error.js @@ -11,31 +11,23 @@ const { ownKeys } = Reflect; // TODO: Maintenance hazard: Coordinate with the list of errors in the SES // whilelist. -// -// @ts-expect-error AggregateError is mistyped below because, for some reason, -// TS is getting TS's definition for ES2021 at -// node_modules/typescript/lib/lib.es2021.promise.d.ts -// rather than TS's definition for ES2022 at -// node_modules/typescript/lib/lib.es2022.error.d.ts -// However, because the constructor parameter types of -// the AggregateErrorConstructor are genuinely different that ErrorConstructor, -// this at-ts-expect-error probably remains. This suggests that we should -// not be using the ErrorConstructor as the type of that part of the `Map` -// call. However, I don't see anywhere we declare that type. And if TS is -// inferring a type, why is it inferring a type too narrow to succeed typing -// the expression it is inferred from? -const errorConstructors = new Map([ - ['Error', Error], - ['EvalError', EvalError], - ['RangeError', RangeError], - ['ReferenceError', ReferenceError], - ['SyntaxError', SyntaxError], - ['TypeError', TypeError], - ['URIError', URIError], +const errorConstructors = new Map( + // Cast because otherwise TS is confused by AggregateError + // See https://github.com/endojs/endo/pull/2042#discussion_r1484933028 + /** @type {Array<[string, ErrorConstructor]>} */ + ([ + ['Error', Error], + ['EvalError', EvalError], + ['RangeError', RangeError], + ['ReferenceError', ReferenceError], + ['SyntaxError', SyntaxError], + ['TypeError', TypeError], + ['URIError', URIError], - // https://github.com/endojs/endo/issues/550 - ['AggregateError', AggregateError], -]); + // https://github.com/endojs/endo/issues/550 + ['AggregateError', AggregateError], + ]), +); export const getErrorConstructor = name => errorConstructors.get(name); harden(getErrorConstructor);