7

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?

1

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Sadly, I am consuming these from NuGet using a package manager that does not unpack them into this hierarchy. I would really like to see the developer rework this into something that behaves correctly without having to manually copy files.
Does the directory hierarchy really matter? Should you be able to /// <reference.../> the type definitions wherever they are (e.g. "../../some/path/angular.d.ts")?
@threed it doesn't really matter. I just said that it is pretty standard to use that path structure. The directory structure will constitute what goes inside the <reference /> but it doesn't have to be the exact structure I used.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.