是否可以获取 .vue 文件中定义的 ts 类型 #8460
Unanswered
vaebe
asked this question in
Help/Questions
Replies: 2 comments 4 replies
-
当然可以。直接export就行。 |
Beta Was this translation helpful? Give feedback.
3 replies
-
<script lang="ts" setup>
const emit = defineEmits<{
(evt: 'inc', val: number): void;
}>();
function increment() {
emit('inc', 7);
}
</script>
<template>
<button @click="increment">Increment</button>
</template> <script lang="ts" setup>
import Control from '~/components/Control.vue';
// 這有沒有辦法直接使用原本定義在 `defineEmits` 的 Type
// 現在是可以這樣用,但有定義 `generic="T extends object"` 就無法了
const increment: InstanceType<typeof Control>['onInc'] = (val) => {
console.log(val); // 7
};
</script>
<template>
<Control @inc="increment" />
</template> 像 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
在组件a中定义了 Test 的ts类型
是否可以通过某种方式导出 Test 类型后让组件 b 使用
Beta Was this translation helpful? Give feedback.
All reactions