My current project involves two TypeScript projects - one is the lib project and the other is the consuming app project. The lib project compiles to a single JS file with a declarations file being generated as well. However, I've noticed that the declarations file includes a reference at the top-
/// <reference path="typings/index.d.ts" />
The issue lies in the fact that the lib project has a typings
directory next to the tsconfig.json
, but this directory should not be referenced in the declarations file. Below is the content of my tsconfig:
{
"compilerOptions": {
"module": "commonjs",
"experimentalDecorators": true,
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"outFile": "proj-lib.js",
"sourceMap": true
},
"include": [
"./js/**/*.ts"
]
}
I'm puzzled as to why these references are included in my declarations file.
Temporary Solution
For now, I'm using gulp-regex-replace
to eliminate references from the declaration files using the following script:
tsResult.dts
.pipe(replace({regex: /\/\/\/\s*<reference[^>]+>\s*/g, replace: ''})) // remove references in declaration file
.pipe(gulp.dest(target));
This solution is less than ideal, so I hope there's a more straightforward tsc (TypeScript Compiler) solution available.