-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Open
Labels
Description
What problem does this feature solve?
it seems that we must create type for a componet when use defineExpose
in typescript , and we can get type hint.
// src/types/index.ts
export type CompInst = {
getString: () => string;
};
// src/Comp.vue
<script setup lang="ts">
import { CompInst } from "./types";
defineExpose<CompInst>({
getString() {
return "hello";
},
});
</script>
<template>
<div>comp1</div>
</template>
// src/App.vue
<script setup lang="ts">
import Comp from "./Comp.vue";
import { CompInst } from "./types";
const compRef = ref<CompInst | null>(null);
// type hint !
compRef.value?.getString();
</script>
<template>
<Comp ref="compRef"></Comp>
</template>
maybe can we resolve type of expose by component directly?
What does the proposed API look like?
// src/App.vue
<script setup lang="ts">
// a inner tool can auto resolve expose type from type of component.
import { resolveExpose } from "vue"
import Comp from "./Comp.vue";
const compRef = ref<resolveExpose<typeof Comp> | null>(null);
// type hint !
compRef.value?.getString();
</script>
<template>
<Comp ref="compRef"></Comp>
</template>
sand4rt and ibrahimBeladiproductdevbook and ibrahimBeladi