【问题标题】:how to define a type for an existing npm plugin module?如何为现有的 npm 插件模块定义类型?
【发布时间】:2020-05-30 04:05:51
【问题描述】:

我尝试将使用nodemailernodemailer-html-to-text 插件的代码库转换为打字稿。

Nodemailer 有 @types 定义,但 nodemailer-html-to-text 没有。

如何为这个模块创建自己的类型定义?


我试图在我的项目中创建一个@types/nodemailer-html-to-text.d.ts 文件:

declare module 'nodemailer-html-to-text' {
}

从这里开始,我希望这个文件导出一个Mail.PluginFunction类型的htmlToText函数定义,但是我不知道该怎么做……

【问题讨论】:

    标签: typescript npm nodemailer


    【解决方案1】:

    在这里找到它module-plugin.d.ts

    declare module 'nodemailer-html-to-text' {
      import * as Mail from 'nodemailer/lib/mailer'
      export function htmlToText(): Mail.PluginFunction
    }
    

    【讨论】:

      猜你喜欢
      • 2020-10-30
      • 2017-02-17
      • 2017-03-06
      • 1970-01-01
      • 2020-05-26
      • 2017-07-30
      • 2019-05-26
      • 2020-11-24
      • 2018-09-30
      相关资源
      最近更新 更多