chore: avoid hard error when inferring types

This commit is contained in:
Evan You 2023-04-20 16:57:36 +08:00
parent 4496456d7d
commit 5c6989557d
1 changed files with 13 additions and 14 deletions

View File

@ -1235,26 +1235,25 @@ export function inferRuntimeType(
try { try {
const types = resolveIndexType(ctx, node, scope) const types = resolveIndexType(ctx, node, scope)
return flattenTypes(ctx, types, scope) return flattenTypes(ctx, types, scope)
} catch (e) { } catch (e) {}
// avoid hard error, fallback to unknown
return [UNKNOWN_TYPE]
}
} }
case 'ClassDeclaration': case 'ClassDeclaration':
return ['Object'] return ['Object']
case 'TSImportType': { case 'TSImportType': {
const sourceScope = importSourceToScope( try {
ctx, const sourceScope = importSourceToScope(
node.argument, ctx,
scope, node.argument,
node.argument.value scope,
) node.argument.value
const resolved = resolveTypeReference(ctx, node, sourceScope) )
if (resolved) { const resolved = resolveTypeReference(ctx, node, sourceScope)
return inferRuntimeType(ctx, resolved, resolved._ownerScope) if (resolved) {
} return inferRuntimeType(ctx, resolved, resolved._ownerScope)
}
} catch (e) {}
} }
default: default: