天天看點

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 語言規範。