Ilya Chernomordik Ilya Chernomordik - 1 month ago 6
TypeScript Question

Does webpack compile Angular2 typescript to javascript?

I have followed Angular2 tutorial to add webpack. I get following errors e.g.:

[default] D:\...\node_modules\@angular\core\src\util\decorators.d.ts:11:4
Property 'extends' of type 'Type<any> | undefined' is not assignable to string index type 'Function | any[] | Type<any>'.[default] D:\...\node_modules\@angular\platform-browser\src\dom\dom_renderer.d.ts:25:21


It seems that webpack tries to compile the whole angular stuff that I reference, which seems a bit too much.

As far as I understand there are already built angular js files that we can use instead of compiling angular (and all other libraries I suppose) each time? Is it possible/reasonable to do so?

Answer

It does whatever you include and tell it to do.

E.g. if you directly import an angular typescript file from your main module (or anything that is included from it) and if you have a loader for typescript configured it will transpile this typescript to javascript.

However if you import a javascript module (like with import { Component } from '@angular/core'. No trailing .ts) it will include that and not transpile anything.;

Your error could also be some problem with type definitions. Which means it already uses the javascript version, but there's somehow a problem with the configured/referenced typescript typings (.d.ts is mentioned) which means the typescript compiler will report an error.