Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8474075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:31:39+00:00 2026-06-10T17:31:39+00:00

I’m trying out Google Closure, specifically the annotating stuff to enforce type safety. To

  • 0

I’m trying out Google Closure, specifically the annotating stuff to enforce type safety. To test I did something wrong, though the compiler won’t tell me that it is…

Here’s the code:

// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level SIMPLE_OPTIMIZATIONS
// ==/ClosureCompiler==

/**
 * A card.
 * @constructor
 * @param {String} cardName The exact name of the card
 * @param {Kinetic.Layer} layer The layer for the card
 */
function CardObject(cardName, layer)
{
    /** @type {Number} */
    var number = cardName;
}

So, I have a variable number which I say is a Number, and I try to assign a string to it. This shouldn’t be possible, right? Though the compiler won’t tell me that…

Why won’t it tell me that’s wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:31:41+00:00Added an answer on June 10, 2026 at 5:31 pm

    Closure Compiler uses warning levels to determine which checks are enabled during the compilation process. The three warning levels are:

    • QUIET
    • DEFAULT
    • VERBOSE

    For example, using compilation level SIMPLE_OPTIMIZATIONS, you will still get type-check warnings with the warning level set to VERBOSE.

    // ==ClosureCompiler==
    // @output_file_name default.js
    // @compilation_level SIMPLE_OPTIMIZATIONS
    // @warning_level VERBOSE
    // ==/ClosureCompiler==
    
    /**
     * A card.
     * @constructor
     * @param {String} cardName The exact name of the card
     * @param {Kinetic.Layer} layer The layer for the card
     */
    function CardObject(cardName, layer)
    {
        /** @type {Number} */
        var number = cardName;
    }
    

    Output

    Number of warnings: 2
    
    JSC_TYPE_PARSE_ERROR: Bad type annotation. Unknown type Kinetic.Layer at line 5
    character 10  
    * @param {Kinetic.Layer} layer The layer for the card
              ^
    JSC_TYPE_MISMATCH: initializing variable
    found   : (String|null|undefined)
    required: (Number|null) at line 10 character 13
    var number = cardName;
                 ^
    

    To understand exactly which checks are associated with each warning level, here is the relevant code from WarningLevels.java.

    QUIET

    /**
     * Silence all non-essential warnings.
     */
    private static void silenceAllWarnings(CompilerOptions options) {
      // Just use a ShowByPath warnings guard, so that we don't have
      // to maintain a separate class of warnings guards for silencing warnings.
      options.addWarningsGuard(
          new ShowByPathWarningsGuard(
              "the_longest_path_that_cannot_be_expressed_as_a_string"));
    
      // Allow passes that aren't going to report anything to be skipped.
    
      options.checkRequires = CheckLevel.OFF;
      options.checkProvides = CheckLevel.OFF;
      options.checkMissingGetCssNameLevel = CheckLevel.OFF;
      options.aggressiveVarCheck = CheckLevel.OFF;
      options.checkTypes = false;
      options.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.OFF);
      options.checkUnreachableCode = CheckLevel.OFF;
      options.checkMissingReturn = CheckLevel.OFF;
      options.setWarningLevel(DiagnosticGroups.ACCESS_CONTROLS, CheckLevel.OFF);
      options.setWarningLevel(DiagnosticGroups.CONST, CheckLevel.OFF);
      options.setWarningLevel(DiagnosticGroups.CONSTANT_PROPERTY, CheckLevel.OFF);
      options.checkGlobalNamesLevel = CheckLevel.OFF;
      options.checkSuspiciousCode = false;
      options.checkGlobalThisLevel = CheckLevel.OFF;
      options.setWarningLevel(DiagnosticGroups.GLOBAL_THIS, CheckLevel.OFF);
      options.setWarningLevel(DiagnosticGroups.ES5_STRICT, CheckLevel.OFF);
      options.checkCaja = false;
    }
    

    DEFAULT

    /**
     * Add the default checking pass to the compilation options.
     * @param options The CompilerOptions object to set the options on.
     */
    private static void addDefaultWarnings(CompilerOptions options) {
      options.checkSuspiciousCode = true;
      options.checkUnreachableCode = CheckLevel.WARNING;
      options.checkControlStructures = true;
    }
    

    VERBOSE

    /**
     * Add all the check pass that are possibly relevant to a non-googler.
     * @param options The CompilerOptions object to set the options on.
     */
    private static void addVerboseWarnings(CompilerOptions options) {
      addDefaultWarnings(options);
    
      // checkSuspiciousCode needs to be enabled for CheckGlobalThis to get run.
      options.checkSuspiciousCode = true;
      options.checkGlobalThisLevel = CheckLevel.WARNING;
      options.checkSymbols = true;
      options.checkMissingReturn = CheckLevel.WARNING;
    
      // checkTypes has the side-effect of asserting that the
      // correct number of arguments are passed to a function.
      // Because the CodingConvention used with the web service does not provide a
      // way for optional arguments to be specified, these warnings may result in
      // false positives.
      options.checkTypes = true;
      options.checkGlobalNamesLevel = CheckLevel.WARNING;
      options.aggressiveVarCheck = CheckLevel.WARNING;
      options.setWarningLevel(
          DiagnosticGroups.MISSING_PROPERTIES, CheckLevel.WARNING);
      options.setWarningLevel(
          DiagnosticGroups.DEPRECATED, CheckLevel.WARNING);
    }
    

    Notice that options.checkTypes = true; is only set for the VERBOSE warning level. As Speransky Danil pointed out, type checking is also enabled when using compilation level ADVANCED_OPTIMIZATIONS.

    In addition, classes of warnings may be controlled individually with the Closure Compiler application (jar file) using compiler flags:

    • –jscomp_off
    • –jscomp_warning
    • –jscomp_error

    The warning classes that may be specified are as follows:

    • accessControls
    • ambiguousFunctionDecl
    • checkRegExp
    • checkTypes
    • checkVars
    • const
    • constantProperty
    • deprecated
    • duplicateMessage
    • es5Strict
    • externsValidation
    • fileoverviewTags
    • globalThis
    • internetExplorerChecks
    • invalidCasts
    • missingProperties
    • nonStandardJsDocs
    • strictModuleDepCheck
    • typeInvalidation
    • undefinedNames
    • undefinedVars
    • unknownDefines
    • uselessCode
    • visibility

    For example, type checking warnings could be enabled individually:

    --jscomp_warning=checkTypes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.