天天看点

Typescript中类型错误解决方案

error TS2351

解决方案

错误详情

错误TS2351:不能将“new”与类型缺少调用或构造签名的表达式一起使用。
Cannot use 'new' with an expression whose type lacks a call or construct signature.           

复制

解决方法

去掉 import 中的 * as           

复制

原因

如:

import * as Router from 'koa-router';

解决方法去掉

* as

,我们直接导入的第三方库的默认导出属性没有任何*或{}.

原因可以查看typescript 语言规范。