Skip to content

Commit 3b5d8d2

Browse files
so11yedison1105autofix-ci[bot]
authored
test(defineProps): add intersection type test (#8684)
Co-authored-by: daiwei <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent aa6879f commit 3b5d8d2

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineProps.spec.ts.snap

+52
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,33 @@ export default /*@__PURE__*/_defineComponent({
233233
234234
235235
236+
return { }
237+
}
238+
239+
})"
240+
`;
241+
242+
exports[`defineProps > w/ extends intersection type 1`] = `
243+
"import { defineComponent as _defineComponent } from 'vue'
244+
type Foo = {
245+
x?: number;
246+
};
247+
interface Props extends Foo {
248+
z: number
249+
y: string
250+
}
251+
252+
export default /*#__PURE__*/_defineComponent({
253+
props: {
254+
z: { type: Number, required: true },
255+
y: { type: String, required: true },
256+
x: { type: Number, required: false }
257+
},
258+
setup(__props: any, { expose: __expose }) {
259+
__expose();
260+
261+
262+
236263
return { }
237264
}
238265
@@ -268,6 +295,31 @@ export default /*@__PURE__*/_defineComponent({
268295
269296
270297
298+
return { }
299+
}
300+
301+
})"
302+
`;
303+
304+
exports[`defineProps > w/ intersection type 1`] = `
305+
"import { defineComponent as _defineComponent } from 'vue'
306+
type Foo = {
307+
x?: number;
308+
};
309+
type Bar = {
310+
y: string;
311+
};
312+
313+
export default /*#__PURE__*/_defineComponent({
314+
props: {
315+
x: { type: Number, required: false },
316+
y: { type: String, required: true }
317+
},
318+
setup(__props: any, { expose: __expose }) {
319+
__expose();
320+
321+
322+
271323
return { }
272324
}
273325

packages/compiler-sfc/__tests__/compileScript/defineProps.spec.ts

+45
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,51 @@ const props = defineProps({ foo: String })
261261
})
262262
})
263263

264+
test('w/ extends intersection type', () => {
265+
const { content, bindings } = compile(`
266+
<script setup lang="ts">
267+
type Foo = {
268+
x?: number;
269+
};
270+
interface Props extends Foo {
271+
z: number
272+
y: string
273+
}
274+
defineProps<Props>()
275+
</script>
276+
`)
277+
assertCode(content)
278+
expect(content).toMatch(`z: { type: Number, required: true }`)
279+
expect(content).toMatch(`y: { type: String, required: true }`)
280+
expect(content).toMatch(`x: { type: Number, required: false }`)
281+
expect(bindings).toStrictEqual({
282+
x: BindingTypes.PROPS,
283+
y: BindingTypes.PROPS,
284+
z: BindingTypes.PROPS,
285+
})
286+
})
287+
288+
test('w/ intersection type', () => {
289+
const { content, bindings } = compile(`
290+
<script setup lang="ts">
291+
type Foo = {
292+
x?: number;
293+
};
294+
type Bar = {
295+
y: string;
296+
};
297+
defineProps<Foo & Bar>()
298+
</script>
299+
`)
300+
assertCode(content)
301+
expect(content).toMatch(`y: { type: String, required: true }`)
302+
expect(content).toMatch(`x: { type: Number, required: false }`)
303+
expect(bindings).toStrictEqual({
304+
x: BindingTypes.PROPS,
305+
y: BindingTypes.PROPS,
306+
})
307+
})
308+
264309
test('w/ exported interface', () => {
265310
const { content, bindings } = compile(`
266311
<script setup lang="ts">

0 commit comments

Comments
 (0)