Skip to content

Commit

Permalink
test: add tests for dts (#3547)
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve authored Sep 12, 2023
1 parent 8eb0bb7 commit e045bd4
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
export interface Props {
msg?: string
labels?: string[]
}
withDefaults(defineProps<Props>(), {
msg: 'hello',
labels: () => ['one', 'two']
})
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
import { ref } from 'vue';
const a = 1;
const b = ref(2);
defineExpose({
a,
b
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup lang="ts" generic="T">
defineProps<{ foo: T }>();
defineEmits<{ (e: 'bar', data: T): void }>();
defineExpose({ baz: {} as T });
defineSlots<{ default?(data: T): any }>();
</script>

<script lang="ts">
declare function defineSlots<T>(): T;
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
defineProps<{
foo: string
bar?: number
}>()
defineEmits<{
(e: 'change', id: number): void
(e: 'update', value: string): void
}>()
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
defineProps({
foo: String
})
defineEmits(['change', 'delete'])
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script setup lang="ts">
defineEmits<{ foo: [string]; }>();
</script>
5 changes: 5 additions & 0 deletions packages/vue-test-workspace/vue-tsc-dts/defineExpose/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script setup lang="ts">
const foo = 123;
defineExpose({ foo });
</script>
11 changes: 11 additions & 0 deletions packages/vue-test-workspace/vue-tsc-dts/defineModel/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
// @ts-nocheck wait for 3.3 added defineModel
import { exactType } from '../../shared';
const a = defineModel<string>(); // modelValue
const c = defineModel<number>('c', { required: true });
const d = defineModel<number>('d', { required: false });
const e = defineModel<string>('e');
const f = defineModel<string>('f', { required: true });
const g = defineModel<string>('g', { required: false });
</script>
20 changes: 20 additions & 0 deletions packages/vue-test-workspace/vue-tsc-dts/defineProp_A/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup lang="ts">
// @experimentalDefinePropProposal=kevinEdition
interface Qux { qux: true; };
defineProp<string>('foo');
defineProp<string>('bar', {
type: String,
required: true,
default: 'bar',
});
defineProp<string | number>('baz', {
required: true,
default: () => [1, 2, 3],
});
defineProp<Qux>('qux');
defineProp<boolean>('quux', { default: true });
// infer prop name from variable name
const quuz = defineProp();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script setup lang="ts" generic="T">
// @experimentalDefinePropProposal=johnsonEdition
const a = defineProp<T>();
const b = defineProp<T>(undefined);
const c = defineProp<T>(undefined, false);
const d = defineProp<T>(undefined, true);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
// @experimentalDefinePropProposal=johnsonEdition
const a = defineProp<string>();
const b = defineProp('', true);
const c = defineProp(1, true);
const d = defineProp(1, false);
const e = defineProp<string>(undefined);
const f = defineProp<string>(undefined, true);
const g = defineProp<string>(undefined, false);
</script>
5 changes: 5 additions & 0 deletions packages/vue-test-workspace/vue-tsc-dts/events/union_type.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script setup lang="ts">
defineEmits<{
(e: "a" | "b", a: string): void;
}>();
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script setup lang="ts" generic="T">
interface Props {
foo: T;
}
defineProps<Props>();
</script>
13 changes: 13 additions & 0 deletions packages/vue-test-workspace/vue-tsc-dts/slots/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<!-- template slots type -->
<slot name="bar" str="str" :num="1"></slot>

<!-- typed slot key -->
<slot :name="baz" str="str" :num="1"></slot>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
const baz = ref('baz' as const);
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { FunctionDirective } from 'vue';
import { exactType } from '../../shared';
let Foo: (_: { foo?: string }) => void;
let Foo: (_: { foo?: string; }) => void;
let vFoo: FunctionDirective<typeof Foo, (_: number) => void>;
</script>
Expand Down
Loading

0 comments on commit e045bd4

Please sign in to comment.