Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kliger (λgeek) <aleksey@lambdageek.org>2022-05-18 15:43:46 +0300
committerGitHub <noreply@github.com>2022-05-18 15:43:46 +0300
commita598ebb67973f03b1d6b3fd6c50f75bae3fe1c51 (patch)
tree9961973e5580b59890bb7c01733539a5888c2297 /src/mono/wasm/runtime
parent41d6dda1dd4698dfa30c84f31237bd40af22a4fb (diff)
[wasm] Give is_nullish() a type guard type (#69473)
* [wasm] Give is_nullish() a type guard type allow callers to refine the type of the argument to just `T` on the false brach ``` let obj: number | null | undefined = ... if (is_nullish (obj)) return; // otherwise obj is known to TS to be 'number'. ```
Diffstat (limited to 'src/mono/wasm/runtime')
-rw-r--r--src/mono/wasm/runtime/strings.ts2
-rw-r--r--src/mono/wasm/runtime/types.ts5
2 files changed, 3 insertions, 4 deletions
diff --git a/src/mono/wasm/runtime/strings.ts b/src/mono/wasm/runtime/strings.ts
index fd864a6b029..715a166d50d 100644
--- a/src/mono/wasm/runtime/strings.ts
+++ b/src/mono/wasm/runtime/strings.ts
@@ -125,7 +125,7 @@ export function mono_intern_string(string: string): string {
const result = interned_string_table.get(ptr);
if (is_nullish(result))
throw new Error("internal error: interned_string_table did not contain string after js_string_to_mono_string_interned");
- return result!;
+ return result;
}
function _store_string_in_intern_table(string: string, root: WasmRoot<MonoString>, internIt: boolean): void {
diff --git a/src/mono/wasm/runtime/types.ts b/src/mono/wasm/runtime/types.ts
index ac738e6ef70..a7e065a6d99 100644
--- a/src/mono/wasm/runtime/types.ts
+++ b/src/mono/wasm/runtime/types.ts
@@ -269,7 +269,6 @@ export const enum MarshalError {
// Evaluates whether a value is nullish (same definition used as the ?? operator,
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator)
-// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-export function is_nullish (value: any): boolean {
+export function is_nullish<T> (value: T | null | undefined): value is null | undefined {
return (value === undefined) || (value === null);
-} \ No newline at end of file
+}