質問

There are probably like three people doing what I'm doing but here goes:

  • Visual Studio 2012
  • Latest Web Essentials
  • TypeScript project
  • AngularJS framework
  • Running Chutzpah tests with Jasmine

When creating tests for Chutzpah, I need to add references not only to my typescript files but also to the javascript libraries that I'm using. For example:

// Typescript References (for tsc)
/// <reference path="../ref/angular-1.0.d.ts" />

// JavaScript references (for chutzpah)
/// <reference path="../lib/angular.min.js" />

// TS references for what we're actually testing...
/// <reference path="../src/modules.ts" />

With this setup, my typescript-authored jasmine tests are running great. However, the angular.min.js file is filling up my error list with hundreds of complaints. This makes it impossible to find errors that are reported by the typescript syntax checker.

If I remove the reference to angular.min.js, then Chutzpah cannot run since my code depends on the library.

Is there a way to force Visual Studio to ignore errors in a particular JavaScript file reference?

役に立ちましたか?

解決

This issue is now solved in Chutzpah 2.4.

Chutzpah Specific Reference

With the addition of TypeScript support a few releases ago several people reported issues when using Chutzpah with the TypeScript plugin in VS. The problem occurs since both TypeScript and Chutzpah are using the comments for different purposes. To get around this issue Chutzpah now supports two ways to reference dependent files.

  1. The existing general way /// <reference path="foo.js" />

  2. The new Chutzpah specific way /// <chutzpah_reference path="foo.js" />

Using the latter will let Chutzpah know about your dependency graph and should not confuse the TypeScript compiler.

他のヒント

This is a bug with Chutzpah which the developer now appears to be aware of:

http://chutzpah.codeplex.com/discussions/404083#post1008911

The problem you have here is that you are including a .js file as a reference.
You should only be using .ts files as references.

Including the .js file is causing TypeScript to treat is as a typescript file, hence the errors.
Have a look on DefinetelyTyped and switch the angular.min.js to the Angular.d.ts file to allow for your TypeScript compilation to pass.

I had the same problem with jasmine tests needing /// comments in order to run. In my case they were needed because I'm using Resharper and want to be able to take advantage of their javascript test runner.

The solution (although, not ideal) is based on the discussion at http://typescript.codeplex.com/workitem/466. As of v9.1.1 typescript, the compiler ignores references that include a space after the '='. So, instead of using

/// <reference path="~/somefile.js"/>

You use this instead:

/// <reference path= "~/somefile.js"/>

Beware: this may break in future versions of Typescript, but, hopefully by then, the language will support a way to include references for javascript files that are ignored by the compiler.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top