2017-01-06 4 views
0

活字体の定義を作成するためのコードVSセットアップへ:私はのための活字体の定義(d.ts)を作成しようとしているJSファイルを持っているどのように私は、この現在のフォルダ構造を持つファイル

project 
└───typings 
│ | index.d.ts 
| FileToMakeTdFor.js 
| FileToMakeTdFor-Tests.ts 

ザ・JSファイルは次のようになります。

"use strict"; 
var FileToMakeTdFor = (function() { 
    function FileToMakeTdFor(config) { 
     ... 
    } 
    FileToMakeTdFor.prototype.example = function() { 
     ... 
    }; 
    return CRMWebAPI; 
}()); 
exports.FileToMakeTdFor = FileToMakeTdFor; 

index.d.tsファイルは次のようになります。

export interface FileToMakeTdFor { 
    new (config:any): FileToMakeTdFor; 
    example(): void; 
} 

そして、私のテストファイルに私はこの書き込みをしようとしている:

let obj = new FileToMakeTdFor(); 
obj.example(); 

コンストラクタでエラーが発生するCannot find name FileToMakeTdFor

テスト用ファイルにindex.d.tsファイルを見つける方法を教えてください。この構造を設定するより良い方法はありますか?

+0

は、このヘルプを行います。 http://stackoverflow.com/a/39237584/1575281 これは2.0.0 –

+0

より前です。コードとテストコードを一緒にコンパイルすると、定義ファイルを作成する必要はありません。それはボックスの外で動作する必要があります。あなたの問題はどこか別のものかもしれません。 – toskv

+0

また、 'FileToMakeTdFor'モジュールをどのようにインポートしていますか? –

答えて

0

Dave Hillierのlinkに特別なおかげです。それは私をタイプスクリプトHandbook for declaration filesに導いてくれます。どうやら私はいくつかの輸出コールを行方不明になった:

/*~ If this module is a UMD module that exposes a global variable 'CRMWebAPI' when 
*~ loaded outside a module loader environment, declare that global here. 
*~ Otherwise, delete this declaration. 
*/ 
export as namespace FileToMakeTdFor; 

/*~ This declaration specifies that the class constructor function 
*~ is the exported object from the file 
*/ 
export = FileToMakeTdFor; 

export interface FileToMakeTdFor { 
    new (config:any): FileToMakeTdFor; 
    example(): void; 
} 

私はexport as namespace FileToMakeTdFor;export = FileToMakeTdFor;行を追加すると、すべてが仕事を始めた...

関連する問題