针对ES6时Typescript中的外部模块

针对ES6时Typescript中的外部模块,typescript,ecmascript-6,koa,es6-module-loader,koa2,Typescript,Ecmascript 6,Koa,Es6 Module Loader,Koa2,随着Typescript 1.7的发布和对async/Wait的支持,我认为现在是试用Typescript的好时机koa@2. 我有一个非常简单的设置,它已经可以工作了: // app.ts /// <reference path="../typings/koa.d.ts" /> import Koa from 'koa'; const app = new Koa(); 当我尝试运行它时,出现以下错误: /Users/andreas/IdeaProjects/project/

随着Typescript 1.7的发布和对async/Wait的支持,我认为现在是试用Typescript的好时机koa@2.

我有一个非常简单的设置,它已经可以工作了:

// app.ts

/// <reference path="../typings/koa.d.ts" />

import Koa from 'koa';

const app = new Koa();
当我尝试运行它时,出现以下错误:

/Users/andreas/IdeaProjects/project/dist/app.js:16
const app = new koa_1.default();
            ^

TypeError: koa_1.default is not a function
    at Object.<anonymous> (/Users/andreas/IdeaProjects/project/dist/app.js:16:13)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:138:18)
    at node.js:974:3
这就解释了为什么它要添加.default,但据我所知,它是在错误的情况下添加的。膝关节炎膝关节炎膝关节炎(不需要)>代码> >“KOA”导入KOA;<代码> >,但当我从<膝关节炎>代码>导入时,作为KOA;< /代码>

<膝关节炎>膝关节炎>编译时,将App.ts中的导入语句更改为<代码>导入>为“KOA”; >生成的App.js工作,但TysScript编译器和IDE给了我以下错误。
src/app.ts(13,13): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
src/app.ts(23,16): error TS7006: Parameter 'ctx' implicitly has an 'any' type.
src/app.ts(23,21): error TS7006: Parameter 'next' implicitly has an 'any' type.
src/app.ts(32,9): error TS7006: Parameter 'ctx' implicitly has an 'any' type.
因此,目前,我可以选择我的开发环境是否工作,或者生成的Javascript是否工作,但不能同时选择两者

处理这个问题的最好办法是什么

<膝关节炎> <> >我认为最简单的事情是改变Ko.D.TS定义文件,将其与代码>导入*匹配为膝关节炎,从'KoA;。但是,我没有设法做到这一点。 感谢您的帮助!

更改此选项:

 export default class Koa {
对此

class Koa {
// ...
namespace Koa { // add all your export interface inside
// ...
export = Koa;

继续使用
import*作为Koa
语法。

检查您是否讨论了这个问题,其中一个工具正在用默认值包装传入的库,而另一个没有。然后查看DefiniteTyped上的一些库,看看它们是如何编写DEF的-我看到的那些库没有使用导出默认值,通常更喜欢
export=
inst放电涂覆处理。
src/app.ts(13,13): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
src/app.ts(23,16): error TS7006: Parameter 'ctx' implicitly has an 'any' type.
src/app.ts(23,21): error TS7006: Parameter 'next' implicitly has an 'any' type.
src/app.ts(32,9): error TS7006: Parameter 'ctx' implicitly has an 'any' type.
 export default class Koa {
class Koa {
// ...
namespace Koa { // add all your export interface inside
// ...
export = Koa;