作为一些打字练习,我试图为一个小型npm库创建一个DefinitelyTyped定义文件。模块的导出如下所示:
module.exports = useNative() ? NativeCustomEvent :
// IE >= 9
'undefined' !== typeof document && 'function' === typeof
document.createEvent ? function CustomEvent (type, params) {...}
// IE < 9
: function CustomEvent(type, params) {...}哪里
useNative是一个布尔函数,CustomEvent返回事件e和var NativeCustomEvent = global.CustomEvent
我只想为这个简单的模块编写一个干净的.d.ts文件。我只是有点迷失了试着去做。任何指示都将不胜感激。
更新:
所以我有了/node-modules/custom-event ( js模块),并在/node-modules/@types/中添加了一个名为/custom-event的文件夹,其中添加了一个custom-event.d.ts
目前为止的代码:
declare module "custom-event" {
function CustomEvent(type: any, params: any): any
export = CustomEvent
}发布于 2017-06-23 22:51:11
如果你不考虑DT,你可以这样做:
// custom-typings/custom-event.d.ts
declare module "custom-event" {
export = CustomEvent
}
// package.json
{
"dependencies": {
"@types/node": ...
}
}
// tsconfig.json
{
"include": [
"custom-typings"
]
}https://stackoverflow.com/questions/44727198
复制相似问题