Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle closure compiler w/ ternaries: ERROR - inconsistent return type
    primarykey
    data
    text
    <p>So I have a helper namespace which I store helpful additions when developing JS. Now I plan to document them better and strengthen my JS with JsDoc and the help of Google Closure compiler. I got the lastest versions as of 2PM today. However I get errors with the when running the compiler on the following code:</p> <pre><code>var my.company.tool = { "isNumber": function( p_value ) { return ( typeof(p_value) == "number" ) ? true : false; }, /** * @static * @returns {Boolean} Indicative of an object. */ "isObject": function( p_value ) { return ( typeof(p_value) == "object" ) ? true : false; } } </code></pre> <p>So on both return lines I get the compiler error "ERROR - inconsistent return type"</p> <p>How do I use ternary operators like this with the Google closure compiler? And yes I've Googled, but I just keep getting irrelevant search results. For now I will remove the ternary but it would prefer to use them without errors:</p> <p>So I updated my statements as suggested by "Tomasz Nurkiewicz", but I'm still getting the errors: Changed made to code:</p> <pre><code>var my.company.tool = { "isNumber": function( p_value ) { return typeof(p_value) == "number"; }, /** * @static * @returns {Boolean} Indicative of an object. */ "isObject": function( p_value ) { return typeof(p_value) == "object"; } } </code></pre> <p>Compiler output: </p> <pre><code>[pakeException] js/core/IHR.js:68: ERROR - inconsistent return type found : boolean required: (Boolean|null) return typeof( p_value ) == "number"; ^ js/core/IHR.js:76: ERROR - inconsistent return type found : boolean required: (Boolean|null) return ( typeof( p_value ) == "object" ); ^ 2 error(s), 0 warning(s), 99.0% typed </code></pre> <p>Even when I try to set the type to {Boolean|null} I still get the errors. What gives?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload