About
Data Type - Static Typing in JavaScript.
Articles Related
Checker
Typing can be added with this method:
- TypeScript (by Microsoft). in Typescript, Type declaration files express the data types of parameters and functions. - - superset of Javascript that compiles plain Javascript
- Flow Static Type Checker (by Facebook)
Documentation Annotation
Jsdoc
in js file: with Typescript checkJs (to true) and Jsdoc Ref
See typescript supports it via Jsdoc
{
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"checkJs": true,
"target": "es2017",
"module": "commonjs"
},
"include": [
"lib"
]
}
Closure
the Google Closure types syntax (works within Idea).
- Simple Type: Type of parameter or variable is specified on the left side
/** @param {number} x **/
function inc(x) {return x + 1;}
- Constructor Type: Every constructor function “becomes” a type and its name can be referenced inside JSDoc tags.
function Point(x,y) { this.x = x; this.y = y; }
/** @param {Array.<Point>} points
* Array of elements of some type could also be specified with [] (for example, Point[]).
*/
function printPoints(points) {
...
}
- It works also for the DOM
// @param {Node} domNode
// @param {HTMLElement} htmlElement
- Return Type
/** @return {!Shape|undefined} */
- Type annotation
/** @type {function(string, *)} */
function