Run code coverage against the generated javascript. You can even hit 100% coverage by telling Istanbul to ignore those pesky impossible-to-call lines that typescript writes.
Istanbul honors comments like /* istanbul ignore next */, so what I do is run a string replace in my gulp task that injects the istanbul ignore comments into the auto-generated wrapper code that TypeScript writes.
Here is the gulp task:
var gulp = require('gulp'),
replace = require('gulp-replace'),
ts = require('gulp-typescript'),
gulp.task('scripts', function () {
//compile typescript into javascript
gulp.src('src/**/*.ts')
.pipe(ts({
declarationFiles: false,
removeComments: false
}))
//write comments to tell istanbul to ignore the code inside the iife parameters
.js.pipe(replace(/(}\)\()(.*\|\|.*;)/g, '$1/* istanbul ignore next */$2'))
//write comments to tell istanbul to ignore the extends code that typescript generates
.pipe(replace(/(var __extends = \(this && this.__extends\))/g, '$1/* istanbul ignore next */'))
//write all of the compiled javascript files to a build folder so we can use them for tests and coverage
.pipe(gulp.dest('dist/src'))
//...the rest of your build process
});
Here is the generated code.
var __extends = (this && this.__extends)/* istanbul ignore next */ || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var animalApi;
(function (animalApi) {
var dogs;
(function (dogs) {
var BlackLab = (function (_super) {
__extends(BlackLab, _super);
//class code...
});
dogs.BlackLab = BlackLab;
})(/* istanbul ignore next */dogs = animalApi.dogs || (animalApi.dogs = {}));
})(/* istanbul ignore next */animalApi || (animalApi = {}));