get 函数要求返回一个 promise 对象,而 return this.name,并不满足,为何编译通过?
直接 return 一个字符串,编译器报错,为什么 return this.name,却可以通过编译?(this.name 实际也是一个字符串)
this.name 是个 any , 因为 this 运行时确定,你也可以手动指定 this
function get(this:string): Promise<string> { this.name = 'zjl'; return this.name; }
@yviscool
this.name 的类型是 any 可是 get 函数要求返回 promise 对象,这样也可以满足吗?
@lyf103104 any全都能过,当然前提是你tsconfig里面允许.
我估计你是想这样写吧
async function get(this: string): Promise<string> { return "" }
@JsonSong89 嗯嗯,谢谢
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
this.name 是个 any , 因为 this 运行时确定,你也可以手动指定 this
@yviscool
this.name 的类型是 any 可是 get 函数要求返回 promise 对象,这样也可以满足吗?
@lyf103104 any全都能过,当然前提是你tsconfig里面允许.
我估计你是想这样写吧
@JsonSong89 嗯嗯,谢谢