【发布时间】:2018-10-17 00:06:56
【问题描述】:
我有一些辅助函数被合并到容器对象中。并且可以从代码中的任何位置调用这些函数。
const Utils = {
isSomeMethod: function (a: INodeType, b: INodeType) {
// Some logic
},
_nodeCheck: function (n: INodeType) {
// `this` : {
// node: INodeType,
// nn: INodeType,
// }
return (n !== this.node && Utils.isSomeMethod(n, this.nn));
},
...
}
该函数可以接受参数以及上下文变量this我有一个问题是否有可能将任何特定类型设置为context variable。
注意:在上面的示例中,方法 _nodeCheck 必须采用类型为 {node: INodeType, nn: INodeType} 的上下文变量(该第 3 方解决方案,我无法更改它)该方法在我的代码中广泛使用,并且我想要进行类型检查。
【问题讨论】:
标签: javascript typescript typescript-typings