Skip to content

Commit

Permalink
Use 'satisfies' instead of 'assertType' (#1364)
Browse files Browse the repository at this point in the history
TypeScript 4.9 shipped with the `satisfies` keyboard which can be used
instead of our custom `assertType` to ensure a value satisfies a given
type.
  • Loading branch information
nmattia authored Mar 27, 2023
1 parent f6980f8 commit 3cbdaf7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/frontend/src/flows/manage/deviceSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "../../utils/iiConnection";
import { displayError } from "../../components/displayError";
import { withLoader } from "../../components/loader";
import { unreachable, unknownToString, assertType } from "../../utils/utils";
import { unreachable, unknownToString } from "../../utils/utils";
import { DeviceData } from "../../../generated/internet_identity_types";
import { phraseRecoveryPage } from "../recovery/recoverWith/phrase";
import { phraseWizard } from "../recovery/setupRecovery";
Expand Down Expand Up @@ -139,7 +139,7 @@ export const resetPhrase = async ({
});
return reload();
} else {
assertType<{ canceled: void }>(res);
res satisfies { canceled: void };
return reload();
}
};
Expand Down
5 changes: 2 additions & 3 deletions src/frontend/src/flows/recovery/setupRecovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
unknownToString,
unreachable,
unreachableLax,
assertType,
} from "../../utils/utils";
import type { ChooseRecoveryProps } from "./chooseRecoveryMechanism";
import { chooseRecoveryMechanism } from "./chooseRecoveryMechanism";
Expand Down Expand Up @@ -158,7 +157,7 @@ export const setupPhrase = async (
} else if ("error" in res) {
return "error";
} else {
assertType<{ canceled: void }>(res);
res satisfies { canceled: void };
return "canceled";
}
};
Expand Down Expand Up @@ -186,7 +185,7 @@ export const phraseWizard = async ({
return { canceled: undefined };
}

assertType<"confirmed">(res);
res satisfies "confirmed";

try {
const pubkey = recoverIdentity.getPublicKey().toDer();
Expand Down
5 changes: 0 additions & 5 deletions src/frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// Ensures the argument has a given type (from ts' perspective, not js)
export function assertType<T>(_: T) {
/* */
}

// Turns an 'unknown' into a string, if possible, otherwise use the default
// `def` parameter.
export function unknownToString(obj: unknown, def: string): string {
Expand Down

0 comments on commit 3cbdaf7

Please sign in to comment.