简体   繁体   中英

Closure Compiler - Bad Type Annotation. Unknown type (with externs)

Starting with the basics. I'm using the JavaScript Closure Compiler and got the error Bad Type Annotation. Unknown type VRPose Bad Type Annotation. Unknown type VRPose I was trying to have a function return a {VRPose} . ie

/**
 * @returns {VRPose}
 */
VRDisplay.prototype.getPose = function() {};

I did the obvious thing and tried to define the VRPose like:

function VRPose() {};

Unfortunately, this didn't work; I have the same error. How should I go about defining a type/class in Closure?

At first, I tried

goog.forwardDeclare('VRPose');

This actually worked fine. And maybe this was correct behavior for defining externs. But it seemed to be to sort of be skirting the problem.

I looked around for a bit more and found that I was missing the @constructor tag. So here's what I have now:

/** @constructor */
function VRPose() {};

I'm not really sure what the difference between these two is, so if anyone would like to answer the question and include a better explanation, I'd be happy to accept!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM