问题描述
我指的是这个类型定义文件:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/nodemailer/index.d.ts,总共有9个导出文件:type
,interface
和function
每个3个文件。
import NM from "nodemailer";
,然后NM
可以访问导出的三个函数:createTestAccount
,createTransport
和getTestMessageUrl
。对于该文件中的其他导出,我必须显式导入,例如:
import { SendMailOptions,Transporter } from "nodemailer";
此类型定义的默认导出在哪里?
在同一项目中,我使用导出创建了自己的测试模块,但未将其声明为默认模块。如果我使用默认语法导入,则编译器会停止运行。
对于module
,我的编译器选项是ES2015(如果有关联的话)。
解决方法
您的allowSyntheticDefaultImports
文件中必须有tsconfig
。 允许从模块默认导入,而没有默认导出。
如果没有默认的导出打字稿,则导入模块就像输入import * as NM from 'nodemailer'