I am just starting out with TypeScript and trying to add it to an existing AngularJS project.
I have 'excluded' the bower directory where angular is installed and downloaded the definitelyTyped definitions for angular in the preferences window.
Angular code completion is working, but typescript is giving me an error TS2304 wherever I code 'angular.'.
What have I missed?
To fix the error, you need to copy the downloaded definitelyTyped TypeScript stubs from ~/Library/Caches/WebStorm9/extLibs
folder to your project directory and reference them in your .ts file using /// <reference path>
comments, like
/// <reference path="path/to/angular.d.ts" />
Just to make things clear:
When you download Typescript stubs via Preferences/Languages & Frameworks/Javascript/libraries, they are placed into ~/Library/Caches/WebStorm9/extLibs
.
It's perfectly fine for Webstorm - it doesn't require placing library files directly in the project folder. Also, Webstorm itself doesn't need ///reference
comments to be able to resolve types - type hinting/navigation/completion works even if the types are not explicitly referenced. But the tsc compiler does need the d.ts files being placed somewhere in the project directory and referenced via ///reference
comment.
So, to get downloaded stubs available to typescript compiler, you need to copy/move them to you project directory (and probably rename to more human readable names :)) and add comments (can be done using 'Generate reference path comment
' intention (hit Alt+Enter on a reference to generate a comment)).
We plan to provide an option to download files directly to the project folder (instead of system/extLibs/ ) in the future versions
probably need to add a reference to the .d.ts in the particular .ts file having the problem, something like:
/// <reference path="../typings/angular.d.ts"/>
downloaded the definitelyTyped definitions for angular in the preferences window.
The intent of downloading the stubs like that is to provide intellisense for JavaScript code not TypeScript code. For TypeScript code you should download and reference the .d.ts
directly in your TypeScript code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With