From dfa005eb7c49704f7d986e5f41c24b2671676003 Mon Sep 17 00:00:00 2001 From: Daniel Chambers Date: Wed, 6 Dec 2023 15:53:54 +1100 Subject: [PATCH] Minor fixes --- src/infer.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/infer.ts b/src/infer.ts index 24832f5..4345bd8 100644 --- a/src/infer.ts +++ b/src/infer.ts @@ -173,8 +173,8 @@ function qualify_type_name(root_file: string, t: any, name: string): string { if (!symbol) { try { symbol = t.types[0].getSymbol(); - } catch { - throw new Error(`Couldn't find symbol for type ${name}`); + } catch (e) { + throw new Error(`Couldn't find symbol for type ${name}`, { cause: e }); } } @@ -224,6 +224,7 @@ function validate_type(root_file: string, checker: ts.TypeChecker, object_type_d return { type: 'array', element_type: inner_type_result }; } + // NULL OR UNDEFINED TYPES (x | null, x | undefined, x | null | undefined) const not_nullable_result = unwrap_nullable_type(ty); if (not_nullable_result !== null) { const [not_nullable_type, null_or_undefinability] = not_nullable_result; @@ -415,12 +416,14 @@ function unwrap_nullable_type(ty: ts.Type): [ts.Type, NullOrUndefinability] | nu const isUndefined = ty.types.find(is_undefined_type) !== undefined; const nullOrUndefinability = isNullable - ? isUndefined - ? NullOrUndefinability.AcceptsEither - : NullOrUndefinability.AcceptsNullOnly - : isUndefined - ? NullOrUndefinability.AcceptsUndefinedOnly - : null; + ? ( isUndefined + ? NullOrUndefinability.AcceptsEither + : NullOrUndefinability.AcceptsNullOnly + ) + : ( isUndefined + ? NullOrUndefinability.AcceptsUndefinedOnly + : null + ); const typesWithoutNullAndUndefined = ty.types .filter(t => !is_null_type(t) && !is_undefined_type(t));