diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index bbed11baffe..870e7c84a8e 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -1618,9 +1618,9 @@ export function inferRuntimeType( return inferRuntimeType(ctx, node.typeAnnotation, scope) case 'TSUnionType': - return flattenTypes(ctx, node.types, scope) + return flattenTypes(ctx, node.types, scope, isKeyOf) case 'TSIntersectionType': { - return flattenTypes(ctx, node.types, scope).filter( + return flattenTypes(ctx, node.types, scope, isKeyOf).filter( t => t !== UNKNOWN_TYPE, ) } @@ -1633,7 +1633,7 @@ export function inferRuntimeType( case 'TSIndexedAccessType': { const types = resolveIndexType(ctx, node, scope) - return flattenTypes(ctx, types, scope) + return flattenTypes(ctx, types, scope, isKeyOf) } case 'ClassDeclaration': @@ -1685,14 +1685,15 @@ function flattenTypes( ctx: TypeResolveContext, types: TSType[], scope: TypeScope, + isKeyOf: boolean = false, ): string[] { if (types.length === 1) { - return inferRuntimeType(ctx, types[0], scope) + return inferRuntimeType(ctx, types[0], scope, isKeyOf) } return [ ...new Set( ([] as string[]).concat( - ...types.map(t => inferRuntimeType(ctx, t, scope)), + ...types.map(t => inferRuntimeType(ctx, t, scope, isKeyOf)), ), ), ]