feat(sfc): support using declared interface or type alias with defineProps()
This commit is contained in:
@@ -780,6 +780,63 @@ return { emit }
|
||||
})"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> with TypeScript defineProps w/ exported interface 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
export interface Props { x?: number }
|
||||
|
||||
export default _defineComponent({
|
||||
props: {
|
||||
x: { type: Number, required: false }
|
||||
} as unknown as undefined,
|
||||
setup(__props: { x?: number }, { expose }) {
|
||||
expose()
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
})"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> with TypeScript defineProps w/ exported type alias 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
export type Props = { x?: number }
|
||||
|
||||
export default _defineComponent({
|
||||
props: {
|
||||
x: { type: Number, required: false }
|
||||
} as unknown as undefined,
|
||||
setup(__props: { x?: number }, { expose }) {
|
||||
expose()
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
})"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> with TypeScript defineProps w/ interface 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
interface Props { x?: number }
|
||||
|
||||
export default _defineComponent({
|
||||
props: {
|
||||
x: { type: Number, required: false }
|
||||
} as unknown as undefined,
|
||||
setup(__props: { x?: number }, { expose }) {
|
||||
expose()
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
})"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> with TypeScript defineProps w/ type 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
|
||||
@@ -840,6 +897,25 @@ export default _defineComponent({
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
})"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> with TypeScript defineProps w/ type alias 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
type Props = { x?: number }
|
||||
|
||||
export default _defineComponent({
|
||||
props: {
|
||||
x: { type: Number, required: false }
|
||||
} as unknown as undefined,
|
||||
setup(__props: { x?: number }, { expose }) {
|
||||
expose()
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
|
||||
@@ -592,6 +592,62 @@ const emit = defineEmits(['a', 'b'])
|
||||
})
|
||||
})
|
||||
|
||||
test('defineProps w/ interface', () => {
|
||||
const { content, bindings } = compile(`
|
||||
<script setup lang="ts">
|
||||
interface Props { x?: number }
|
||||
defineProps<Props>()
|
||||
</script>
|
||||
`)
|
||||
assertCode(content)
|
||||
expect(content).toMatch(`x: { type: Number, required: false }`)
|
||||
expect(bindings).toStrictEqual({
|
||||
x: BindingTypes.PROPS
|
||||
})
|
||||
})
|
||||
|
||||
test('defineProps w/ exported interface', () => {
|
||||
const { content, bindings } = compile(`
|
||||
<script setup lang="ts">
|
||||
export interface Props { x?: number }
|
||||
defineProps<Props>()
|
||||
</script>
|
||||
`)
|
||||
assertCode(content)
|
||||
expect(content).toMatch(`x: { type: Number, required: false }`)
|
||||
expect(bindings).toStrictEqual({
|
||||
x: BindingTypes.PROPS
|
||||
})
|
||||
})
|
||||
|
||||
test('defineProps w/ type alias', () => {
|
||||
const { content, bindings } = compile(`
|
||||
<script setup lang="ts">
|
||||
type Props = { x?: number }
|
||||
defineProps<Props>()
|
||||
</script>
|
||||
`)
|
||||
assertCode(content)
|
||||
expect(content).toMatch(`x: { type: Number, required: false }`)
|
||||
expect(bindings).toStrictEqual({
|
||||
x: BindingTypes.PROPS
|
||||
})
|
||||
})
|
||||
|
||||
test('defineProps w/ exported type alias', () => {
|
||||
const { content, bindings } = compile(`
|
||||
<script setup lang="ts">
|
||||
export type Props = { x?: number }
|
||||
defineProps<Props>()
|
||||
</script>
|
||||
`)
|
||||
assertCode(content)
|
||||
expect(content).toMatch(`x: { type: Number, required: false }`)
|
||||
expect(bindings).toStrictEqual({
|
||||
x: BindingTypes.PROPS
|
||||
})
|
||||
})
|
||||
|
||||
test('withDefaults (static)', () => {
|
||||
const { content, bindings } = compile(`
|
||||
<script setup lang="ts">
|
||||
|
||||
Reference in New Issue
Block a user