diff --git a/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts b/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts index dc859f3338c..c7e2b9b694a 100644 --- a/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts @@ -207,6 +207,38 @@ describe('resolveType', () => { }) }) + test('utility type: Partial', () => { + expect( + resolve(` + type T = { foo: number, bar: string } + defineProps>() + `).raw.props + ).toMatchObject({ + foo: { + optional: true + }, + bar: { + optional: true + } + }) + }) + + test('utility type: Required', () => { + expect( + resolve(` + type T = { foo?: number, bar?: string } + defineProps>() + `).raw.props + ).toMatchObject({ + foo: { + optional: false + }, + bar: { + optional: false + } + }) + }) + test('utility type: Pick', () => { expect( resolve(` diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index 79ee2567035..526569843ec 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -513,8 +513,20 @@ function resolveBuiltin( ): ResolvedElements { const t = resolveTypeElements(ctx, node.typeParameters!.params[0]) switch (name) { - case 'Partial': - case 'Required': + case 'Partial': { + const res: ResolvedElements = { props: {}, calls: t.calls } + Object.keys(t.props).forEach(key => { + res.props[key] = { ...t.props[key], optional: true } + }) + return res + } + case 'Required': { + const res: ResolvedElements = { props: {}, calls: t.calls } + Object.keys(t.props).forEach(key => { + res.props[key] = { ...t.props[key], optional: false } + }) + return res + } case 'Readonly': return t case 'Pick': {