2016-09-06 67 views
0

我有一個項目是用腳本編寫的(lib項目),並由另一個用腳本編寫的項目(應用程序項目)使用。 lib項目編譯爲一個js文件並生成一個聲明文件。一切正常,但生成的聲明文件中包含的頂級爲什麼使用引用生成Typescript聲明?

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

這個參考的lib項目有旁tsconfig.json一個typings目錄,但它只是需要的lib項目。它不應該被包含在聲明文件中作爲參考。這是我的tsconfig

{ 
    "compilerOptions": { 
     "module": "commonjs", 
     "experimentalDecorators": true, 
     "declaration": true, 
     "noImplicitAny": false, 
     "removeComments": true, 
     "preserveConstEnums": true, 
     "outFile": "proj-lib.js", 
     "sourceMap": true 
    }, 
    "include": [ 
     "./js/**/*.ts" 
    ] 
} 

爲什麼我的聲明文件包含引用?

治標不治本

使用gulp-regex-replace刪除從申報文件的引用。

tsResult.dts 
      .pipe(replace({regex: /\/\/\/\s*<reference[^>]+>\s*/g, replace: ''})) // remove references in declaration file 
      .pipe(gulp.dest(target)); 

這並不理想。我希望有一個tsc解決方案。

回答

0

檢查文檔爲打字稿編譯器選項:)

https://www.typescriptlang.org/docs/handbook/compiler-options.html

--declaration布爾(默認)錯誤產生相應的「.d.ts」文件。

只有當您把需要分型(.d.ts文件)引用

如果關你tsconfig(選擇第3行)應該消失。

乾杯

+0

我不明白你的答案。我想'd.ts'文件,但我不想在那些生成的文件中引用。 –

相關問題