Weird behavior for @typedef

This resides in classes.js

/** @typedef {{ _id:ObjectID, nuid:String, size:Array.<Number>, cap:Number, cost:Object, r : { i:Object, s:Object } }} */
BuildingBlueprint;

This resides in another js file;

/** @type {BuildingBlueprint} */
var building = category[ buildingIndex ];
building.cap = 10; //cap has a warning with "Property cap is not defined in.."; But dot then ctrl+space autocomplete does show it!


Now I did the serveral things:
changed BuildingBlueprint to "var BuildingBlueprint = null";
did this: /** @typedef {{ _id:ObjectID, nuid:String, size:Array.<Number>, cap:Number, cost:Object, r : { i:Object, s:Object } }} BuildingBlueprint */
tried using @type instead with the combinations above.

What happens is that sometimes cap doesn't have this warning, but when I try to add an object with the same exact structure, that value throws an error that its not compatible or something of the sorts.

I found @typedef and @type to be extremely poor documentated on the internet.

I need to know if I am using it wrong or if there is some sort of a bug. Thank you!

1 comment

You are using @type and @typedef properly. And your code works fine for me (tried both WebStorm 6 and WebStorm 7 RC). The problem might be caused by some other code in your files that break the type hinting...

0

Please sign in to leave a comment.