未明确定义默认导出

问题描述

我指的是这个类型定义文件https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/nodemailer/index.d.ts,总共有9个导出文件typeinterfacefunction每个3个文件

文件中没有定义认导出。但是,我可以执行以下操作:

import NM from "nodemailer";

,然后NM可以访问导出的三个函数createTestAccountcreateTransportgetTestMessageUrl。对于该文件中的其他导出,我必须显式导入,例如:

import { SendMailOptions,Transporter } from "nodemailer";

此类型定义的认导出在哪里?

在同一项目中,我使用导出创建了自己的测试模块,但未将其声明为认模块。如果我使用认语法导入,则编译器会停止运行。

对于module,我的编译器选项是ES2015(如果有关联的话)。

解决方法

您的allowSyntheticDefaultImports文件中必须有tsconfig允许从模块默认导入,而没有默认导出。

如果没有默认的导出打字稿,则导入模块就像输入import * as NM from 'nodemailer'