Skip to content

Commit 30e944b

Browse files
committed
fix(compiler-sfc): fallback to UNKNOWN when unable to infer keyof operator, fix #11002
1 parent 560a5f9 commit 30e944b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,21 @@ describe('resolveType', () => {
535535
})
536536
})
537537

538+
test('keyof: fallback to UNKNOWN', () => {
539+
const { props } = resolve(
540+
`
541+
interface Barr {}
542+
interface Bar extends Barr {}
543+
type Foo = keyof Bar
544+
defineProps<{ foo: Foo }>()
545+
`,
546+
)
547+
548+
expect(props).toStrictEqual({
549+
foo: ['UNKNOWN'],
550+
})
551+
})
552+
538553
test('ExtractPropTypes (element-plus)', () => {
539554
const { props, raw } = resolve(
540555
`

packages/compiler-sfc/src/script/resolveType.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ export function inferRuntimeType(
14961496
}
14971497
}
14981498

1499-
return types.size ? Array.from(types) : ['Object']
1499+
return types.size ? Array.from(types) : [isKeyOf ? 'UNKNOWN' : 'Object']
15001500
}
15011501
case 'TSPropertySignature':
15021502
if (node.typeAnnotation) {

0 commit comments

Comments
 (0)