隐式具有类型“any”,因为它没有类型注释

implicitly has type 'any' because it does not have a type annotation

提问人:KaMZaTa 提问时间:10/2/2023 更新时间:10/2/2023 访问量:36

问:

我有这个功能:

enter image description here

我从 Typescript 收到此错误消息:'this' implicitly has type 'any' because it does not have a type annotation.

enter image description here

下面是文本中的函数:

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)

有什么想法吗?

打字稿

评论


答: 暂无答案