2016-10-04 67 views
0

我想在Typescript中使用異步庫;我已經安裝了定義文件,是由分型提供,但我不能使用AsyncFunction:Nodejs,Typescript,typings:如何使用異步庫

///<reference path='typings/index.d.ts' /> 
'use strict'; 

import async = require('async'); 

let functions : AsyncFunction<any>[] = []; 

如果我編譯該提取物我得到這個錯誤:

tsc test.ts --target es2015 --module system --removeComments --forceConsistentCasingInFileNames --noEmitOnError --noFallthroughCasesInSwitch --noImplicitAny --noImplicitReturns --noImplicitUseStrict --declaration --outfile a.js 
test.ts(4,17): error TS2304: Cannot find name 'AsyncFunction'. 

我使用的異步定義文件這個:https://raw.githubusercontent.com/types/npm-async/ff63908a70ec51b775d9a6b8afac9945b12fbe08/2/index.d.ts

我做錯了什麼?

謝謝!

+0

如果有人遇到同樣的問題,我的解決方案是安裝全局定義dt〜async – Steve81

回答

0

接口AsyncFunction不從該文件中導出。唯一的出口是async,你可以從最後一行的export = async;看到。

修復

隨意 interface AsyncFunction<T> { (callback: (err?: Error, result?: T) => void): void; }複製到global.d.ts,如果你必須使用註解。

+0

謝謝,我明白爲什麼我很困惑:異步v1定義不使用「模塊」,因此所有接口都是直接可獲取的。 – Steve81

+0

@ Steve81能否詳細解釋爲什麼會發生這種錯誤 – blackHawk