Skip to content

Commit

Permalink
fix(compiler-sfc): fallback to UNKNOWN when unable to infer keyof ope…
Browse files Browse the repository at this point in the history
…rator, fix #11002
  • Loading branch information
jh-leong committed May 24, 2024
1 parent 560a5f9 commit 193d65d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,21 @@ describe('resolveType', () => {
})
})

test('keyof: fallback to Unknown', () => {
const { props } = resolve(
`
interface Barr {}
interface Bar extends Barr {}
type Foo = keyof Bar
defineProps<{ foo: Foo }>()
`,
)

expect(props).toStrictEqual({
foo: ['Unknown'],
})
})

test('ExtractPropTypes (element-plus)', () => {
const { props, raw } = resolve(
`
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,9 @@ export function inferRuntimeType(
}
}

return types.size ? Array.from(types) : ['Object']
return types.size
? Array.from(types)
: [isKeyOf ? UNKNOWN_TYPE : 'Object']
}
case 'TSPropertySignature':
if (node.typeAnnotation) {
Expand Down

0 comments on commit 193d65d

Please sign in to comment.