From 6b194bcf3b8143895c2a472cd87998ebf9856146 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 8 May 2023 12:30:19 +0800 Subject: [PATCH] fix(compiler-sfc): fix built-in type resolving in external files close #8244 --- .../__tests__/compileScript/resolveType.spec.ts | 17 +++++++++++++++++ packages/compiler-sfc/src/script/resolveType.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts b/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts index 551e10237dc..4b36880bf1b 100644 --- a/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts @@ -475,6 +475,23 @@ describe('resolveType', () => { expect(deps && [...deps]).toStrictEqual(Object.keys(files)) }) + // #8244 + test('utility type in external file', () => { + const files = { + '/foo.ts': 'type A = { n?: number }; export type B = Required' + } + const { props } = resolve( + ` + import { B } from './foo' + defineProps() + `, + files + ) + expect(props).toStrictEqual({ + n: ['Number'] + }) + }) + test('relative vue', () => { const files = { '/foo.vue': diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index 2fa8d028c65..550b6c23767 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -518,7 +518,7 @@ function resolveBuiltin( name: GetSetType, scope: TypeScope ): ResolvedElements { - const t = resolveTypeElements(ctx, node.typeParameters!.params[0]) + const t = resolveTypeElements(ctx, node.typeParameters!.params[0], scope) switch (name) { case 'Partial': { const res: ResolvedElements = { props: {}, calls: t.calls }