【发布时间】:2020-01-19 23:18:23
【问题描述】:
我正在尝试将 JavaScript 中的无渲染组件转换为 TypeScript。我在 Vue.extend-ed 组件中声明 render 函数时遇到错误:
(method) ComponentOptions<Vue, unknown, unknown, unknown, never[], Record<never, any>>.render?(createElement: CreateElement, hack: RenderContext<Record<never, any>>): VNode
No overload matches this call.
The last overload gave the following error.
Argument of type '{ render(): void; }' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>'.
Types of property 'render' are incompatible.
Type '() => void' is not assignable to type '(createElement: CreateElement, hack: RenderContext<Record<string, any>>) => VNode'.
Type 'void' is not assignable to type 'VNode'.ts(2769)
vue.d.ts(90, 3): The last overload is declared here.
这是我在 TypeScript 中尝试做的一个示例:
import Vue from 'vue'
export default Vue.extend({
render() { // error happens when I add this. I tried typing the render with :VNode
// and returning this.$scopedSlots.default({}), but error still occurs
}
})
我该如何解决这个问题?
【问题讨论】:
-
你是什么意思 - 将道具发送回父组件?可以分享原始代码sn-p吗?
-
learn-vuejs.github.io/vue-patterns/patterns/… 这是一个无渲染组件,这是我只想用打字稿实现的目标
标签: typescript vue.js vuejs2 vue-component renderless-component