fix(compiler-sfc): handle keyof operator with index object (#11581)

This commit is contained in:
disservin 2024-08-15 04:24:04 +02:00 committed by GitHub
parent e9e08155bf
commit fe008152c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 1 deletions

View File

@ -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(
`

View File

@ -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':