Building a class registry: Cannot use 'new' with an expression whose type lacks a call or construct signature

一世执手 提交于 2019-11-29 08:54:14

import Base = require(...) does not mix well with export default class Base.

If you add console.dir(Base) to things.ts, you will see that Base is actually a module there, not a class:

{ __esModule: true, default: [Function: Base] }

If you change that import in things.ts to

import Base from './things/Base';

then your example starts working.

The explanation is given in the typescript language specification:

An import require declaration of the form

    import m = require("mod");

is equivalent to the ECMAScript 2015 import declaration

    import * as m from "mod";

That es6 form always imports m as a module, even if it contains default export.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!