From bbacbb08b6b4adaac2277f9f0e4775c8d565b1f7 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 8 Jul 2024 14:20:43 +0530 Subject: [PATCH] doc --- web/packages/utils/ensure.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/packages/utils/ensure.ts b/web/packages/utils/ensure.ts index 41639ea2b5..d37ccf359c 100644 --- a/web/packages/utils/ensure.ts +++ b/web/packages/utils/ensure.ts @@ -1,5 +1,10 @@ /** * Throw an exception if the given value is `null` or `undefined`. + * + * This is different from TypeScript's built in null assertion operator `!` in + * that `ensure` involves a runtime check, and will throw if the given value is + * null-ish. On the other hand the TypeScript null assertion is only an + * indication to the type system and does not involve any runtime checks. */ export const ensure = (v: T | null | undefined): T => { if (v === null) throw new Error("Required value was null");