@xxx("xxx")
class A{
msg:string
constructor(msg:string) {
this.msg = msg
}
print() {
console.log(this.msg)
}
}
function xxx(arg:string) {
function f(target) {
function ff(msg: string) {
return new target(arg + ":" + msg)
}
return ff
}
return f
}
let a = new A("hellow")
a.print()
Run Code Online (Sandbox Code Playgroud)
编译时,报告:
decorator.ts(1,1):错误TS1238:当作为表达式调用时,无法解析类装饰器的签名.类型'(msg:string)=> any'不能分配给'void'类型.
但是生成的js执行得很好.我不知道为什么报错.
typescript ×1