Skip to content

Commit 560a5f9

Browse files
committed
fix(compiler-sfc): handle keyof operator w/ Pick and Extract utility types
1 parent 41ab9db commit 560a5f9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,16 @@ describe('resolveType', () => {
510510
type Foo = Record<symbol | string, any>
511511
type Bar = { [key: string]: any }
512512
type AnyRecord = Record<keyof any, any>
513+
type Baz = { a: 1, ${1}: 2, b: 3}
513514
514515
defineProps<{
515516
record: keyof Foo,
516517
anyRecord: keyof AnyRecord
517518
partial: keyof Partial<Bar>,
518519
required: keyof Required<Bar>,
519520
readonly: keyof Readonly<Bar>,
521+
pick: keyof Pick<Baz, 'a' | 1>
522+
extract: keyof Extract<keyof Baz, 'a' | 1>
520523
}>()
521524
`,
522525
)
@@ -527,6 +530,8 @@ describe('resolveType', () => {
527530
partial: ['String'],
528531
required: ['String'],
529532
readonly: ['String'],
533+
pick: ['String', 'Number'],
534+
extract: ['String', 'Number'],
530535
})
531536
})
532537

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

+10
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,16 @@ export function inferRuntimeType(
15591559
)
15601560
}
15611561
break
1562+
case 'Pick':
1563+
case 'Extract':
1564+
if (node.typeParameters && node.typeParameters.params[1]) {
1565+
return inferRuntimeType(
1566+
ctx,
1567+
node.typeParameters.params[1],
1568+
scope,
1569+
)
1570+
}
1571+
break
15621572

15631573
case 'Function':
15641574
case 'Object':

0 commit comments

Comments
 (0)