【发布时间】:2021-12-18 11:06:30
【问题描述】:
type Animal = {
name: string
}
function getBear(this: Animal) : Animal {
this.name = "hi"
return this
}
console.log(getBear().name)
谁能帮我解决这个问题,我无法调用 getBear 函数
【问题讨论】:
-
您明确定义
this必须是Animal,但是您在没有对象上调用getBear所以它是void。
标签: javascript typescript typescript-typings