2016-03-04 56 views
0

我們使用JavaScript庫在我們的項目如下:創建定時器機打字稿定義文件

timer-machine

我嘗試瞭如下定義:我試圖在應用程序內

//timer-machine.d.ts 

declare module "timer-machine" { 
    export class Timer{} 
} 

以下列方式使用它:

import {Timer} from "timer-machine"; 
... 
let timer = new Timer() 

,但我得到了以下錯誤:

Uncaught TypeError: _timerMachine.Timer is not a constructor 

我究竟怎樣才能改變我的定義,就像是在該庫的描述中我至少可以instatiate定時器嗎?

任何幫助,將不勝感激。

回答

1

經歷的基本用法:

var Timer = require('timer-machine') 
var myTimer = new Timer() 

你可以看到,定時器應在。所以:

//timer-machine.d.ts 

declare module "timer-machine" { 
    class Timer{} 
    export = Timer; 
}