How to use isolatedDeclarations with defineComponent in typescript #14434
Replies: 2 comments 1 reply
-
|
下面是在启用 ✅ 核心思路
✅ 推荐做法 1:显式导出 Props/Emits 类型export interface FadeInExpandTransitionProps {
group?: boolean
appear?: boolean
width?: boolean
mode?: 'default' | 'in-out' | 'out-in'
onLeave?: () => void
onAfterLeave?: () => void
onAfterEnter?: () => void
}然后: export default defineComponent({
props: {
// ...使用 PropType 显式标注
} as PropType<FadeInExpandTransitionProps>,
})好处: ✅ 推荐做法 2:
|
| 问题 | 规避 |
|---|---|
通过 PropType<typeof something> 推断链很长 |
改用显式 interface |
| 条件类型 + infer 组合 | 拆成明确类型别名 |
| 导出 default defineComponent 直接推断 | 用 const X = defineComponent(...); export type Props = ...; export default X |
✅ 结论(给你一个最实用的答案)
想“优雅声明组件”,而不是手写长类型:
✅ 把 props/emits 类型显式抽到 interface
✅ 用 satisfies 或 defineProps<T>() 固定推断
✅ 让每个文件声明可独立生成
Beta Was this translation helpful? Give feedback.
-
|
Hello @Mister-Hope, Working with Vue reactivity system and compilers can sometimes present interesting edge cases. A few quick things to consider regarding this topic:
I highly recommend checking out the Vue DevTools extension to inspect the component tree and verify if the state is updating as expected. Let me know if you want to dig deeper into the specific component logic. Hope this points you in the right direction! Let me know how it goes. Happy coding! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I am trying to speed up with oxc, I need to enable isolatedDeclarations for dts generation.
However, I do not see any possibility to write a detailed type by hand. Is there anyway to "declare these components" gracefully?
Beta Was this translation helpful? Give feedback.
All reactions