visual-studio-2015amdtypescript-typingsumdtypescript2.2

AMD RequireJS @types TypeScript 2 Visual Studio 2015 nightmare


I'm assigned a task to update our angularJs project to TypeScript 2

We currently use requirejs (AMD) to shim libraries, then use

import 'angular'; import 'lodash';

which is an ES6 module loading syntax as far as I can understand. We declare a main Application module and import libraries in it, then as we import the Application module

import 'Application';

which is also shimed by requirejs, we automatically get all the list of imported libraries of Application as we import it.


I actually updated the project SUCCESSFULLY to TypeScript 2!!!

However, the problem arises when I try to use @types to include TypeScript Declaration files.

There is not a single complete reference on how to do the job!

****** The Question! ******

When I tried to use @types/lodash I lost intellisense for _ (lodash) in all existing files.

When I attempt to

import * as _ from 'lodash';

I'm then faced with a different error:

Build:Module augmentation cannot introduce new names in the top level scope.

My understanding is that the .d.ts files export UMD modules. But how can I reference the @types in my Visual Studio 2015?

Please help! And Thanks.


Solution

  • requireJS doen NOT handle UMD (Universal Module Loading) gracefully. All @types libraries are UMD libraries.

    We had to move to WebPack in order to get @types libraries to load properly.

    Most importantly, we had done so as a step closer to upgrading to Angular 5, which cannot be accessed by requireJS AMD, since it was written in TypeScript as a UMD from the start.