I\'m starting writing AngularJS app using TypeScript. I have this simple module command:
(() => {
angular
.module(\'app\', []);
})();
<
Using AngularJS 1.x and TypeScript 2.x, I solved this issue by running:
npm install --save-dev @types/angular
and then include the following line on top of the .ts file:
import * as angular from "angular";
Reference: The Future of Declaration Files
You could simplistically tell the compiler to stop worrying by telling it that "you know all about angular":
declare var angular: any;
To get all the good tooling and type checking, you need to pull in the Angular type definition so the compiler knows what is available.
The type definitions are available via NuGet if you are using Visual Studio or various other methods for your favourite IDE.
ATOM
In tsconfig.json
file ensure your "fileGlobs"
points to both:-
tsd
&src .ts files
"filesGlob": [
"./typings/**/*.ts",
"./src/client/**/*.ts"
]
This will ensure you have tooling for the libraries you have installed (with tsd
) without having to declare
any variables. For example, if you tsd install angularjs --save
, you can work angular
in your src/../*.ts files
with all the goody tooling.
Hope this helps. Good Luck.
You need to include angular.t.ds file in the library
I solved the problem by adding the following line to my package.json, inside the "devDependencies" section:
"@types/angular" : "1.6.17"
after that, i just needed to run
npm install
in order for npm to download all the needed dependencies.
For me inside of VisualStudio I used part of Augusto's suggested answer and simply did:
npm install --save @types/angular
and it worked like a charm.