Skip to content

Instantly share code, notes, and snippets.

@Skateside
Last active December 17, 2015 03:49
Show Gist options
  • Save Skateside/5546361 to your computer and use it in GitHub Desktop.
Save Skateside/5546361 to your computer and use it in GitHub Desktop.
This is a simple exploration of the Google Closure Compiler's use of JSDoc and the @type's needed to validate the code.
/*
General notes:
Curly braces around the types seem to be optional. "{number}" works the same as
"number".
*/
/**
* @type {boolean} bool
*/
var bool = true;
/**
* @type {number} num
*/
var num = 1;
/**
* @type {string} str
*/
var str = '';
/**
* "null", "Null" and "Object" seem to work here.
*
* @type {null} nul
*/
var nul = null;
/**
* @type {undefined} undef
*/
var undef = undefined;
/**
* @type {Array} arr
*/
var arr = [];
/**
* @type {Object} obj
*/
var obj = {};
/**
* @type {RegExp} reg
*/
var reg = /a/;
/**
* @type {Function} fn
*/
var fn = function () {};
/**
* @type {Date} date
*/
var date = new Date();
/**
* The constructor tag is needed or the "Foo" type will not be recognised.
*
* @constructor
*/
function Foo() {
}
/**
* @type {Foo} foo
*/
var foo = new Foo();
/**
* @type {Element} dom
*/
var dom = document.createElement('p');
/**
* The asterisk denotes any type or "mixed"
*
* @type {*} mixed
*/
var mixed = ['a', 1, {}, []][Math.floor(Math.random() * 4)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment