Definitelytyped: Angular/Angular-Resource/Lodash TS1316 errors 'TS1316:Global module exports may only appear at top level' after update last version.

Created on 14 Dec 2016  路  17Comments  路  Source: DefinitelyTyped/DefinitelyTyped

Today angular.d.ts, angular-resource.d.ts, lodash.d.ts update
WTF?

1234

Most helpful comment

This is such a mess. Some libraries are still stuck providing globals, some have umd modules. The paths between their community provided .d.ts files and the actual file to use at run time also don't line up ( and typescript won't rewrite urls, so then you need rollup ).

So yet again I am forced to determine what stupdity is needed to make TSC happy.

In my case, I am running into a similair issue with sockjs-client and its typings

I know you want to drag javascript kicking and screaming into modern times. But until that point we need to work with existing libraries. This kind of stuff needs to be spelled out in documents, maybe a section on "Fixing common module pitfalls", or a switch to tsc to "Shut up, just turn these warnings off, it will be a global at runtime"

Yet another day wasted jumping through needless hoops.

All 17 comments

same

Same here too

same here

Same...

This is due to #13280 and the switch to types-2.0. If you're using typings, see typings/typings#738.

Same here

Same

Same.

same

Can anyone please post the exact solution here?

halp

same

I finally managed to solve this today with the help of this article. As mentioned in the Typings issue:

Typings can not install anything using "export as namespace"

And this is true for the angular definitions. So instead of typings I used npm to install the angular definitions:

npm install @types/angular --save

to resolve the dependency issue, I installed typescript, too (might not be required):

npm install typescript

Finally I added

import * as angular from "angular";

at the top of my file, below the already existing

/// <reference path="../../typings/index.d.ts" /> reference.

Best solution I found so far, without including import * as angular from 'angular' everywhere :

  1. Use @ types instead of typings
  2. Create a new file globals.d.ts
import * as _angular from 'angular';
declare global {
  const angular: typeof _angular;
}
  1. Add
/// <reference path="./globals.d.ts" />

In your main entrypoint

This is such a mess. Some libraries are still stuck providing globals, some have umd modules. The paths between their community provided .d.ts files and the actual file to use at run time also don't line up ( and typescript won't rewrite urls, so then you need rollup ).

So yet again I am forced to determine what stupdity is needed to make TSC happy.

In my case, I am running into a similair issue with sockjs-client and its typings

I know you want to drag javascript kicking and screaming into modern times. But until that point we need to work with existing libraries. This kind of stuff needs to be spelled out in documents, maybe a section on "Fixing common module pitfalls", or a switch to tsc to "Shut up, just turn these warnings off, it will be a global at runtime"

Yet another day wasted jumping through needless hoops.

EDIT: I hadn't included the other modules in the project file - some days you forget to check the simple things

Hey @Wykks @Nostrus - thanks for that!

Any ideas on how would you include other angular modules like angular-route in your solution?

I've tried declaring the constant as a union type like below...

import * as _angular from 'angular';
import * as _angular_route from 'angular-route';
import * as _angular_animate from 'angular-animate';

declare global {
    const angular: typeof _angular | _angular_route | _angular_animate ;
}

and bunch of other stuff with no luck.

Was this page helpful?
0 / 5 - 0 ratings