[英]Definitions file for simple js module
I am trying to make a DefinitelyTyped definition file for a small npm commonjs library as some typescript practice. 我正在尝试为小型npm commonjs库制作一个DefinitelyTyped定义文件,作为一些打字稿练习。 The module's exports looks like this: 该模块的导出如下所示:
module.exports = useNative() ? NativeCustomEvent :
// IE >= 9
'undefined' !== typeof document && 'function' === typeof
document.createEvent ? function CustomEvent (type, params) {...}
// IE < 9
: function CustomEvent(type, params) {...}
where 哪里
useNative
is a boolean function, and CustomEvent
returns an event e and var NativeCustomEvent = global.CustomEvent
useNative
是一个布尔函数, CustomEvent
返回事件e,并且var NativeCustomEvent = global.CustomEvent
I just want to write a clean .d.ts file for this simple module. 我只想为这个简单的模块编写一个干净的.d.ts文件。 I am just getting a bit lost with trying to do it. 我只是迷失于尝试这样做。 Any pointers would be greatly appreciated. 任何指针将不胜感激。
Update: 更新:
So i have /node-modules/custom-event
(the js module) and added to /node-modules/@types/
a folder called /custom-event
where I added a custom-event.d.ts
所以我有/node-modules/custom-event
(js模块)并添加到/node-modules/@types/
一个名为/custom-event
的文件夹,在其中添加了custom-event.d.ts
code so far: 到目前为止的代码:
declare module "custom-event" {
function CustomEvent(type: any, params: any): any
export = CustomEvent
}
If you don't consider DT, you can do this: 如果您不考虑DT,则可以执行以下操作:
// custom-typings/custom-event.d.ts
declare module "custom-event" {
export = CustomEvent
}
// package.json
{
"dependencies": {
"@types/node": ...
}
}
// tsconfig.json
{
"include": [
"custom-typings"
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.