From 5c6989557dafb7f7b3d2bb225618c83c70a4e12e Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 20 Apr 2023 16:57:36 +0800 Subject: [PATCH] chore: avoid hard error when inferring types --- .../compiler-sfc/src/script/resolveType.ts | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index f5a52401bb..1dc8b16ead 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -1235,26 +1235,25 @@ export function inferRuntimeType( try { const types = resolveIndexType(ctx, node, scope) return flattenTypes(ctx, types, scope) - } catch (e) { - // avoid hard error, fallback to unknown - return [UNKNOWN_TYPE] - } + } catch (e) {} } case 'ClassDeclaration': return ['Object'] case 'TSImportType': { - const sourceScope = importSourceToScope( - ctx, - node.argument, - scope, - node.argument.value - ) - const resolved = resolveTypeReference(ctx, node, sourceScope) - if (resolved) { - return inferRuntimeType(ctx, resolved, resolved._ownerScope) - } + try { + const sourceScope = importSourceToScope( + ctx, + node.argument, + scope, + node.argument.value + ) + const resolved = resolveTypeReference(ctx, node, sourceScope) + if (resolved) { + return inferRuntimeType(ctx, resolved, resolved._ownerScope) + } + } catch (e) {} } default: -- 2.39.5