Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using @types/angular as global

I'm currently trying to update my angular 1 application from typings to @types.

First I got following error message:

Identifier 'angular' must be imported from a module

After some searching I found out, that angular isn't accessible globally anymore. Or anleast I didn't find out how...


With typings, angular was global and I could use it without imports or anything. My problem is, that an import of angular, like this:

import * as angular from 'angular';

breaks my application: Unfortunately SystemJS is now trying to load angular and because of this it's not available when ui-bootstrap and other libs are loaded with script tags.

To fix this, I would have to rewrite a huge part of the build-pipeline. So I'm asking again: Is there another way to use angular with TypeScript 2 and @types, that doesn't end in a require('angular')?

like image 748
Dinistro Avatar asked Oct 17 '22 22:10

Dinistro


1 Answers

I found the answer. Do this and everything will work finr.

import * as _angular_ from 'angular';

declare global {
  const angular: typeof _angular_;
}
like image 74
AngularOne Avatar answered Oct 20 '22 16:10

AngularOne