JSDoc error? Argument type null is not assignable to parameter type string. Follow
I'm getting a warning in my Javascript code that I'm afraid I don't understand. If you create the following:
/**
* @param {string} aParam Some parameter.
*/
function myFunction(aParam) {
}
myFunction(null);
The IDEA displays a warning on the "null" saying "Argument type null is not assignable to parameter type string". If I change the case of the type in the JSDoc from {string} to {String} then the warning goes away. I'm somewhat new to Javascript but this seems like it should be a legitimate method call and that this warning is a bug. Am I missing something?
I'm running IDEA 2016.2 #IU-162.1121.32.
Please sign in to leave a comment.
You will get similar error when using Closure Compiler online (http://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520SIMPLE_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540warning_level%2520verbose%2520%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F%252F%2520ADD%2520YOUR%2520CODE%2520HERE%250A%252F**%250A*%2520%2540param%2520%257Bstring%257D%2520aParam%2520Some%2520parameter.%250A*%252F%250Afunction%2520myFunction(aParam)%2520%257B%250A%250A%257D%250AmyFunction(null)%253B%250A, make sure to add `// @warning_level verbose` to see the warnings :
JSC_TYPE_MISMATCH: actual parameter 1 of myFunction does not match formal parameter found : null required: string at line 8 character 11
myFunction(null);
Null type is a special type in javaScript (http://www.ecma-international.org/ecma-262/5.1/#sec-4.3.12)