Why I get the error message: (45, 1) TS2304: Cannot find the name 'angular'. in webstorm

I am just starting out with TypeScript and trying to add it to an existing AngularJS project.

I have an β€œexcluded” bower directory where angular is installed and loaded with specific definitions for angular in the settings window.

Angular does the completion of the code, but TypeScript gives me the TS2304 error, wherever I go, code angular. '.

What did I miss?

+7
angularjs webstorm typescript
source share
3 answers

To fix the error, you need to copy the defintyped TypeScript loaded stubs from ~/Library/Caches/WebStorm9/extLibs to your project directory and link to them in your .ts file using /// <reference path> comments, for example

 /// <reference path="path/to/angular.d.ts" /> 

Just to make everything clear: When you load TypeScript stubs through Preferences / Languages ​​and Frameworks / Javascript / libraries, they are placed in ~/Library/Caches/WebStorm9/extLibs . It is great for Webstorm - it does not require placing library files directly in the project folder. In addition, Webstorm does not need ///reference comments to be able to allow hinting / navigation / completion type operations, even if types are not explicitly specified. But the tsc compiler really needs d.ts files located somewhere in the project directory and referencing the ///reference comment. Thus, to get the loaded stubs available for the TypeScript compiler, you need to copy / move them to the project directory (and probably rename them to readable names :)) and add comments (can be done using the 'Generate reference path comment 'intent (press Alt + Enter for a link to create a comment)). We plan to provide the ability to upload files directly to the project folder (instead of system / extLibs /) in future versions

+12
source share

you may need to add a link to .d.ts in a specific .ts file that has a problem, something like:

 /// <reference path="../typings/angular.d.ts"/> 
+2
source share

loaded specific definitions for angular in the settings window.

The goal of loading such stubs is to provide intellisense code for JavaScript code, not TypeScript. For TypeScript code, you must download and link to .d.ts directly in TypeScript code.

+1
source share

All Articles