mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): handle keyof operator with index object (#11581)
This commit is contained in:
parent
e9e08155bf
commit
fe008152c0
|
@ -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(
|
||||
`
|
||||
|
|
|
@ -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':
|
||||
|
|
Loading…
Reference in New Issue