-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Annotating Types
usmonster edited this page May 14, 2014
·
12 revisions
The compiler recognizes @type annotations in two contexts: declarations and casts.
/** @type {function():string} */
function f() {return 'str'}
/** @type {string} */
var x = 'fruit';
or
var /** @type {string} */ x = 'fruit';
/** @type {string} */
x.prop = 'fruit';
or
var x = {
/** @type {string} */
prop : 'fruit'
};
try {
...
} catch (/** @type {string} */ e) {
...
}
Type cast precede a parenthesized expression.
var x = /** @type {string} */ (fruit);