How to use isolatedDeclarations with defineComponent in typescript #14434
Unanswered
Mister-Hope
asked this question in
Help/Questions
Replies: 1 comment 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.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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