From 885ec726bde8fb4373f68faa4ee1ec005069def5 Mon Sep 17 00:00:00 2001 From: zhmushan Date: Fri, 20 Oct 2023 09:58:11 +0800 Subject: [PATCH] fix(compile-sfc): Support define Error as prop type --- .../compileScript/__snapshots__/defineProps.spec.ts.snap | 1 + .../compiler-sfc/__tests__/compileScript/defineProps.spec.ts | 3 +++ packages/compiler-sfc/src/script/resolveType.ts | 1 + 3 files changed, 5 insertions(+) diff --git a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap index 30e00e518b2..5b0f96c5014 100644 --- a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap @@ -232,6 +232,7 @@ export default /*#__PURE__*/_defineComponent({ alias: { type: Array, required: true }, method: { type: Function, required: true }, symbol: { type: Symbol, required: true }, + error: { type: Error, required: true }, extract: { type: Number, required: true }, exclude: { type: [Number, Boolean], required: true }, uppercase: { type: String, required: true }, diff --git a/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts b/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts index 43f54b0aa1e..674d697a597 100644 --- a/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts @@ -97,6 +97,7 @@ const props = defineProps({ foo: String }) alias: Alias method(): void symbol: symbol + error: Error extract: Extract<1 | 2 | boolean, 2> exclude: Exclude<1 | 2 | boolean, 2> uppercase: Uppercase<'foo'> @@ -143,6 +144,7 @@ const props = defineProps({ foo: String }) expect(content).toMatch(`alias: { type: Array, required: true }`) expect(content).toMatch(`method: { type: Function, required: true }`) expect(content).toMatch(`symbol: { type: Symbol, required: true }`) + expect(content).toMatch(`error: { type: Error, required: true }`) expect(content).toMatch( `objectOrFn: { type: [Function, Object], required: true },` ) @@ -198,6 +200,7 @@ const props = defineProps({ foo: String }) alias: BindingTypes.PROPS, method: BindingTypes.PROPS, symbol: BindingTypes.PROPS, + error: BindingTypes.PROPS, objectOrFn: BindingTypes.PROPS, extract: BindingTypes.PROPS, exclude: BindingTypes.PROPS, diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index 78581432366..e8a97bcdb25 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -1391,6 +1391,7 @@ export function inferRuntimeType( case 'WeakMap': case 'Date': case 'Promise': + case 'Error': return [node.typeName.name] // TS built-in utility types