I want to use Angularjs
with TypeScript
.
To solve TS2095: Could not find symbol 'angular'
error, I downloaded ts
files from here and added references to controllers.ts
like this:
/// <reference path="angular.d.ts" />
/// <reference path="jquery.d.ts" />
var mathML = angular.module('mathML', []);
But I still have similar error like this:
angular.d.ts(33,28): error TS2095: Could not find symbol 'JQuery'.
How can I solve this error?
Is there better way to setup environment to use Angularjs
with TypeScript
?
Guide to using TypeScript in AngularJS applications. Supporting older AngularJS applications doesn't mean you can't take advantage of modern tools like TypeScript. Not every file in your application needs to be written in TypeScript at once, you just can rename all your JavaScript files to have a . ts extension.
Angular is a modern framework built entirely in TypeScript, and as a result, using TypeScript with Angular provides a seamless experience. The Angular documentation not only supports TypeScript as a first-class citizen, but uses it as its primary language.
TypeScript is a primary language for Angular application development. It is a superset of JavaScript with design-time support for type safety and tooling. Browsers can't execute TypeScript directly. Typescript must be "transpiled" into JavaScript using the tsc compiler, which requires some configuration.
You can write Angular applications in either TypeScript, ES6 or even ES5 JavaScript. However Angular itself is written in TypeScript, most examples on the web are written in TypeScript, most Angular jobs require you to write TypeScript so this book will be teaching in TypeScript.
Using the following directory structure :
|- angular
|- angular.d.ts
|- jquery
|- jquery.d.ts
|- mathML.ts
I was able to get the following sample code to compile without errors.
/// <reference path="angular/angular.d.ts" />
var mathML = angular.module('mathML', []);
The angular.d.ts file references the jquery.d.ts file using a relative path. The directory structure is pretty standard for 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