Skip to content

Commit

Permalink
fix(compiler-sfc): handle keyof operator usage w/ Record utility type
Browse files Browse the repository at this point in the history
  • Loading branch information
jh-leong committed May 13, 2024
1 parent b2b5f57 commit d896b67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,13 @@ describe('resolveType', () => {
const { props } = resolve(
`
import { IMP } from './foo'
interface Foo { foo: 1, ${1}: 1 }
interface Foo { foo: 1, ${1}: 1 }
type Bar = { bar: 1 }
declare const obj: Bar
declare const set: Set<any>
declare const arr: Array<any>
defineProps<{
defineProps<{
imp: keyof IMP,
foo: keyof Foo,
bar: keyof Bar,
Expand All @@ -483,6 +483,23 @@ describe('resolveType', () => {
})
})

// #10920
test('keyof: Record utility type', () => {
const { props } = resolve(
`
type AnyRecord = Record<keyof any, any>
type Props<PObj extends AnyRecord> = {
foo: keyof PObj
}
defineProps<Props<AnyRecord>>()
`,
)

expect(props).toStrictEqual({
foo: ['Symbol', 'String', 'Number'],
})
})

test('ExtractPropTypes (element-plus)', () => {
const { props, raw } = resolve(
`
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,8 @@ export function inferRuntimeType(
case 'ArrayLike':
case 'ReadonlyArray':
return ['String', 'Number']
case 'Record':
return ['Symbol', 'String', 'Number']
default:
return ['String']
}
Expand Down

0 comments on commit d896b67

Please sign in to comment.