Skip to content

Commit

Permalink
fixup! review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Feb 10, 2024
1 parent 17d8a5d commit 0c98c96
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions packages/pass-style/src/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0c98c96

Please sign in to comment.