Skip to content

Commit 3caa0c3

Browse files
committed
fix(compiler-sfc): handle keyof operator usage w/ Record utility type
1 parent b2b5f57 commit 3caa0c3

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

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

+21-2
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,13 @@ describe('resolveType', () => {
455455
const { props } = resolve(
456456
`
457457
import { IMP } from './foo'
458-
interface Foo { foo: 1, ${1}: 1 }
458+
interface Foo { foo: 1, ${1}: 1 }
459459
type Bar = { bar: 1 }
460460
declare const obj: Bar
461461
declare const set: Set<any>
462462
declare const arr: Array<any>
463463
464-
defineProps<{
464+
defineProps<{
465465
imp: keyof IMP,
466466
foo: keyof Foo,
467467
bar: keyof Bar,
@@ -483,6 +483,25 @@ describe('resolveType', () => {
483483
})
484484
})
485485

486+
test('keyof: Record utility type', () => {
487+
const { props } = resolve(
488+
`
489+
type Foo = Record<symbol | string, any>
490+
type AnyRecord = Record<keyof any, any>
491+
492+
defineProps<{
493+
foo: keyof Foo,
494+
anyRecord: keyof AnyRecord
495+
}>()
496+
`,
497+
)
498+
499+
expect(props).toStrictEqual({
500+
foo: ['Symbol', 'String'],
501+
anyRecord: ['Unknown'],
502+
})
503+
})
504+
486505
test('ExtractPropTypes (element-plus)', () => {
487506
const { props, raw } = resolve(
488507
`

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

+6
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,12 @@ export function inferRuntimeType(
15351535
case 'ArrayLike':
15361536
case 'ReadonlyArray':
15371537
return ['String', 'Number']
1538+
case 'Record':
1539+
return inferRuntimeType(
1540+
ctx,
1541+
node.typeParameters!.params[0],
1542+
scope,
1543+
)
15381544
default:
15391545
return ['String']
15401546
}

0 commit comments

Comments
 (0)