2016-03-24 141 views
1

我覺得自己想做的事情很簡單,但是我的編譯器一直告訴我:「不能在表達式中使用new缺少調用或構造簽名。在Typescript定義文件中定義類

我想要做的就是在定義文件中定義一個類,而不是一個接口。我的代碼的簡化版本如下:

declare module jsforce { 

    declare class Connection { 

     constructor(params: ConnectionParams); 

    } 
} 

declare module "jsforce" { 
    var jsforce: jsforce.JSForce; 
    export = jsforce; 
} 

的頁面裏,我發現了錯誤的:

/// <reference path="../typings/jsforce.d.ts" /> 
import jsforce = require('jsforce'); 

// Wapper for JSForce 
export class JSForce { 

    public connection: jsforce.Connection; 

    constructor() { 

    } 

    connect(params: jsforce.ConnectionParams) { 
    this.connection = new jsforce.Connection({}) 
    } 

} 

我在做什麼錯?

回答

0

下編譯只是最新的打字稿罰款:

jsforce.d.ts:

declare module jsforce { 

    class Connection 
    { 
     constructor(params: string); 
    } 
} 

declare module "jsforce" 
{ 
    export = jsforce; 
} 

app.ts

import jsforce = require('jsforce'); 

// Wapper for JSForce 
export class JSForce 
{ 

    public connection: jsforce.Connection; 

    constructor() 
    { 

    } 

    connect(params: jsforce.Connection) 
    { 
     this.connection = new jsforce.Connection('12') 
    } 
}