Skip to content

Commit

Permalink
refactor(permission-controller): Simplify switch in updatePermissions…
Browse files Browse the repository at this point in the history
…ByCaveat
  • Loading branch information
rekmarks committed Apr 19, 2024
1 parent 632ebc9 commit fdf32e1
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions packages/permission-controller/src/PermissionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,8 @@ export class PermissionController<
// The mutator may modify the caveat value in place, and must always
// return a valid mutation result.
const mutatorResult = mutator(targetCaveat.value);
switch (mutatorResult.operation) {
const { operation } = mutatorResult;
switch (operation) {
case CaveatMutatorOperation.noop:
break;

Expand Down Expand Up @@ -1383,15 +1384,9 @@ export class PermissionController<
break;

default: {
// This type check ensures that the switch statement is
// exhaustive.
const exhaustiveCheck: never = mutatorResult;
throw new Error(
`Unrecognized mutation result: "${
// @ts-expect-error We need to override the "never"
exhaustiveCheck.operation
}"`,
);
// Overriding as `never` is the expected result of exhaustiveness checking, and is intended to represent unchecked exception cases.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Unrecognized mutation result: "${operation}"`);
}
}
});
Expand Down

0 comments on commit fdf32e1

Please sign in to comment.