提问人:KaMZaTa 提问时间:10/2/2023 更新时间:10/2/2023 访问量:36
隐式具有类型“any”,因为它没有类型注释
implicitly has type 'any' because it does not have a type annotation
问:
我有这个功能:
我从 Typescript 收到此错误消息:'this' implicitly has type 'any' because it does not have a type annotation.
下面是文本中的函数:
async function compileTemplate(templateName: any, data: any) {
const filePath = path.join(process.cwd(), "pdf/templates", `${templateName}.hbs`)
const html = await fs.readFile(filePath, "utf8")
Handlebars.registerHelper("if_equal", function (a, b, opts) {
if (a == b) {
return opts.fn(this)
} else {
return opts.inverse(this)
}
})
return Handlebars.compile(html)(data)
}
即使我传递类型,错误也不会消失:
return opts.fn<any>(this)
有什么想法吗?
答: 暂无答案
上一个:此指针和链表
评论