diff --git a/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts b/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts index b8b71878e03..ff33882568e 100644 --- a/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts @@ -596,6 +596,65 @@ describe('resolveType', () => { }) }) + test('keyof: nested object with number', () => { + const { props } = resolve( + ` + interface Type { + deep: { + 1: any + } + } + + defineProps<{ + route: keyof Type['deep'] + }>()`, + ) + + expect(props).toStrictEqual({ + route: ['Number'], + }) + }) + + test('keyof: nested object with string', () => { + const { props } = resolve( + ` + interface Type { + deep: { + foo: any + } + } + + defineProps<{ + route: keyof Type['deep'] + }>()`, + ) + + expect(props).toStrictEqual({ + route: ['String'], + }) + }) + + test('keyof: nested object with intermediate', () => { + const { props } = resolve( + ` + interface Type { + deep: { + foo: any + } + } + + type Foo = Type['deep'] + + defineProps<{ + route: keyof Foo + }>()`, + ) + + expect(props).toStrictEqual({ + route: ['String'], + }) + }) + test('ExtractPropTypes (element-plus)', () => { const { props, raw } = resolve( ` diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index 398d3ba9f42..c7880578e7a 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -1703,7 +1703,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':