Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for dts #3547

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
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>
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
Loading