diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index 473ebd4e0b9..f20d16dda8d 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -1625,6 +1625,7 @@ export default /*#__PURE__*/_defineComponent({ literalUnionNumber: { type: Number, required: true }, literalUnionMixed: { type: [String, Number, Boolean], required: true }, intersection: { type: Object, required: true }, + intersection2: { type: String, required: true }, foo: { type: [Function, null], required: true } }, setup(__props: any, { expose }) { diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts index 7616c58f27b..af4dcf21507 100644 --- a/packages/compiler-sfc/__tests__/compileScript.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts @@ -970,6 +970,7 @@ const emit = defineEmits(['a', 'b']) literalUnionNumber: 1 | 2 | 3 | 4 | 5 literalUnionMixed: 'foo' | 1 | boolean intersection: Test & {} + intersection2: 'foo' & ('foo' | 'bar') foo: ((item: any) => boolean) | null }>() `) @@ -1008,6 +1009,7 @@ const emit = defineEmits(['a', 'b']) `literalUnionMixed: { type: [String, Number, Boolean], required: true }` ) expect(content).toMatch(`intersection: { type: Object, required: true }`) + expect(content).toMatch(`intersection2: { type: String, required: true }`) expect(content).toMatch(`foo: { type: [Function, null], required: true }`) expect(bindings).toStrictEqual({ string: BindingTypes.PROPS, @@ -1036,6 +1038,7 @@ const emit = defineEmits(['a', 'b']) literalUnionNumber: BindingTypes.PROPS, literalUnionMixed: BindingTypes.PROPS, intersection: BindingTypes.PROPS, + intersection2: BindingTypes.PROPS, foo: BindingTypes.PROPS }) }) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 3cca3c2f436..f5de1a7b110 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -2069,6 +2069,7 @@ function inferRuntimeType( case 'TSParenthesizedType': return inferRuntimeType(node.typeAnnotation, declaredTypes) case 'TSUnionType': + case 'TSIntersectionType': return [ ...new Set( [].concat( @@ -2076,8 +2077,6 @@ function inferRuntimeType( ) ) ] - case 'TSIntersectionType': - return ['Object'] case 'TSSymbolKeyword': return ['Symbol']