From 3cbdaf7514fda72855721032a6505a3b5c52c646 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Mon, 27 Mar 2023 12:29:29 +0200 Subject: [PATCH] Use 'satisfies' instead of 'assertType' (#1364) 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. --- src/frontend/src/flows/manage/deviceSettings.ts | 4 ++-- src/frontend/src/flows/recovery/setupRecovery.ts | 5 ++--- src/frontend/src/utils/utils.ts | 5 ----- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/flows/manage/deviceSettings.ts b/src/frontend/src/flows/manage/deviceSettings.ts index b7f41017ab..138f4f4434 100644 --- a/src/frontend/src/flows/manage/deviceSettings.ts +++ b/src/frontend/src/flows/manage/deviceSettings.ts @@ -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"; @@ -139,7 +139,7 @@ export const resetPhrase = async ({ }); return reload(); } else { - assertType<{ canceled: void }>(res); + res satisfies { canceled: void }; return reload(); } }; diff --git a/src/frontend/src/flows/recovery/setupRecovery.ts b/src/frontend/src/flows/recovery/setupRecovery.ts index f413fed84b..480046e8f4 100644 --- a/src/frontend/src/flows/recovery/setupRecovery.ts +++ b/src/frontend/src/flows/recovery/setupRecovery.ts @@ -14,7 +14,6 @@ import { unknownToString, unreachable, unreachableLax, - assertType, } from "../../utils/utils"; import type { ChooseRecoveryProps } from "./chooseRecoveryMechanism"; import { chooseRecoveryMechanism } from "./chooseRecoveryMechanism"; @@ -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"; } }; @@ -186,7 +185,7 @@ export const phraseWizard = async ({ return { canceled: undefined }; } - assertType<"confirmed">(res); + res satisfies "confirmed"; try { const pubkey = recoverIdentity.getPublicKey().toDer(); diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index bfb96c3ffb..51173daf81 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -1,8 +1,3 @@ -// Ensures the argument has a given type (from ts' perspective, not js) -export function assertType(_: T) { - /* */ -} - // Turns an 'unknown' into a string, if possible, otherwise use the default // `def` parameter. export function unknownToString(obj: unknown, def: string): string {