2
我尝试在名称空间(L.DomEvent.on(e)
)中写入函数的类型定义,该函数返回this
。 JavaScript的源代码就像返回该名称空间中函数的类型定义
L.DomEvent = {
// @function on(el: HTMLElement, eventMap: Object, context?: Object): this
on: function(e) {
// do stuff
return this;
}
}
予先写的定义如下
declare namespace L {
export namespace DomEvent {
export function on(el: HTMLScriptElement): this;
}
}
但是,编译器会引发错误与消息
error TS2526: A 'this' type is available only in a non-static member of a class or interface.
虽然我可以将输出从this
改变any
(它的工作原理),I想知道是否有更好的解决方案来定义输出。