Relative template URLs for Angular2 components
The new Angular2 Animation DSL

Tired of waiting for TypeScript compilation?

Compiling (or transpiling) TypeScript into JavaScript takes some time. And with many TypeScript files it takes even longer. But what could you do to speed things up?

There is one compilation option you may stumble upon: isolatedModules

By setting this to true, the compilation times will be incredible fast. But why is this happening? The reason is, that the TypeScript compiler doesn't do any type checking anymore with this option switched on. You may ask yourself "Isn't TypeScript also for explicit type checking and why should I switch this off?". Yes that is true, but during development you should not wait for the transpiler over and over. And if you use a modern IDE (e.g. WebStorm, VS Code) the IntelliSense will guide you and show the type problems during writing the code.

A common gulp task for transpiling TypeScript code with sourcemaps for an Angular2 SPA would look like this (I even don't use a project anymore):

gulp.task('build:scripts', () => {
return gulp.src(['./src/app/**/*.ts', './typings/browser.d.ts'], { base: './src' })
.pipe(sourcemaps.init())
.pipe(typescript({
target: 'ES5',
module: 'system',
moduleResolution: 'node',
sourceMap: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
removeComments: false,
noImplicitAny: false,
isolatedModules: true
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./build'));
});

Finally you should switch this option to false (which is also the default value), of course, when you build a release version of your code to have an explicit last type check by the compiler. Or think about a build server which also does the type checking after you pushed your changes during continuous integration. There are many ways to ensure that the final result is still completely type checked, but during development you should save this time for better things.

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

The comments to this entry are closed.