diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index a9a6f236778..d71f41b8002 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -761,7 +761,8 @@ export default _defineComponent({ union: { type: [String, Number], required: true }, literalUnion: { type: [String, String], required: true }, literalUnionMixed: { type: [String, Number, Boolean], required: true }, - intersection: { type: Object, required: true } + intersection: { type: Object, required: true }, + foo: { type: [Function, null], required: true } } as unknown as undefined, setup(__props: { string: string @@ -787,6 +788,7 @@ export default _defineComponent({ literalUnion: 'foo' | 'bar' literalUnionMixed: 'foo' | 1 | boolean intersection: Test & {} + foo: ((item: any) => boolean) | null }, { expose }) { expose() diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts index 42cb84f97fb..4b701bf373e 100644 --- a/packages/compiler-sfc/__tests__/compileScript.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts @@ -514,6 +514,7 @@ const emit = defineEmits(['a', 'b']) literalUnion: 'foo' | 'bar' literalUnionMixed: 'foo' | 1 | boolean intersection: Test & {} + foo: ((item: any) => boolean) | null }>() `) assertCode(content) @@ -545,6 +546,7 @@ const emit = defineEmits(['a', 'b']) `literalUnionMixed: { type: [String, Number, Boolean], required: true }` ) expect(content).toMatch(`intersection: { type: Object, required: true }`) + expect(content).toMatch(`foo: { type: [Function, null], required: true }`) expect(bindings).toStrictEqual({ string: BindingTypes.PROPS, number: BindingTypes.PROPS, @@ -567,7 +569,8 @@ const emit = defineEmits(['a', 'b']) union: BindingTypes.PROPS, literalUnion: BindingTypes.PROPS, literalUnionMixed: BindingTypes.PROPS, - intersection: BindingTypes.PROPS + intersection: BindingTypes.PROPS, + foo: BindingTypes.PROPS }) }) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 05b8c8a50b0..0aab4d2855e 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -1646,6 +1646,8 @@ function inferRuntimeType( } return [`null`] + case 'TSParenthesizedType': + return inferRuntimeType(node.typeAnnotation, declaredTypes) case 'TSUnionType': return [ ...new Set( @@ -1654,7 +1656,6 @@ function inferRuntimeType( ) as any) ) ] - case 'TSIntersectionType': return ['Object']