質問

I have a simple example:

var obj = {
  /**
  * @param {number} inp 
  * @returns {number} returning number plus one
  */
  func: function(inp) {
    return inp++;
  },
  c: 'hello',
  q: null
};

obj.func($(document)); // passing invalid parameter

I would like to see a warning about the passed parameter not being a number but the only way to get that is to set at least to verbose.

It works if I use:

obj.func(" "); // passing invalid parameter

And leave out the --externs jquery-1.9.1.js command parameter. As soon as I combine it with jquery and setting warning_level to verbose (I want to see warnings about invalid casting/parameters/...) I get drowned with 5.5 thousand warnings in the jquery file.

The thing is that I don't care about the jquery warnings but have to include it with --externs or I only get one error:

variable $ is undeclared

Now I am wondering; how do people use this? I'd like to strongly type my javascript but using external libraries I either get no warnings, get flushed with warnings or warnings about missing 3rd party libraries.

Have been at it for hours and really hoping there is better documentation than what google is offering because hasn't been much use so far.

役に立ちましたか?

解決

In most cases, the raw source of a library doesn't make a good extern file. In jQuery's case, you need to use the official extern files found in the Closure-compiler project contrib folder.

There isn't yet a jQuery 1.9 extern file, but I'll see about getting one posted soon. Unless you are using an api signature introduced in 1.9, the 1.8 extern file should suffice.

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