Closure-compiler: Losing type information - "Property get never defined on formData of type FormData"

Created on 13 Apr 2017  路  10Comments  路  Source: google/closure-compiler

Hi all,

I'm getting some strange compiler warnings. It's like the compiler forgets the externs for FormData - see here:

[npm 04/13/17 2:30:27] nps-plugin/index.js:150: WARNING - Property get never defined on formData of type FormData
[npm 04/13/17 2:30:27]           this.userName || formData.get('user_name'),
[npm 04/13/17 2:30:27]                            ^^^^^^^^^^^^
[npm 04/13/17 2:30:27] 
[npm 04/13/17 2:30:27] nps-plugin/index.js:152: WARNING - Property get never defined on formData of type FormData
[npm 04/13/17 2:30:27]           formData.get('score'),
[npm 04/13/17 2:30:27]           ^^^^^^^^^^^^
[npm 04/13/17 2:30:27] 
[npm 04/13/17 2:30:27] nps-plugin/index.js:153: WARNING - Property get never defined on formData of type FormData
[npm 04/13/17 2:30:27]           this.productId || formData.get('product_id'),
[npm 04/13/17 2:30:27]                             ^^^^^^^^^^^^
[npm 04/13/17 2:30:27] 
[npm 04/13/17 2:30:27] nps-plugin/index.js:154: WARNING - Property get never defined on formData of type FormData
[npm 04/13/17 2:30:27]           formData.get('comments')));

I'm not sure if it's related, but the properties on the Form elements elements property seem to be obfuscated as well:

I have to use form.elements['score'].value rather than what I had before, which was form.elements.score.value. Come to think of it, since the "score" element is dynamically defined (and thusly the compiler'd have no way of preserving the token), I have no idea why that was working before...

Here's my compiler info:

VERSION: 20161201.0.0

FLAGS:
java -jar
node_modules/google-closure-compiler/compiler.jar
--js="nps-plugin/index.js"
--js="node_modules/google-closure-library/closure/goog/.js"
--js="!node_modules/google-closure-library/closure/goog/_test.js"
--dependency_mode=STRICT
--compilation_level=ADVANCED_OPTIMIZATIONS
--entry_point=lnkd.NpsPlugin
--output_wrapper="(function(){%output%})();"
--new_type_inf
--jscomp_warning=newCheckTypes
--jscomp_off=newCheckTypesExtraChecks
--hide_warnings_for=node_modules/google-closure-library/
--output_manifest="build/report/manifest.MF"
--js_output_file=nps-plugin.js

Let me know if you can help... thanks so much!

Most helpful comment

All 10 comments

Can you file an issue internally, with steps for me how to build your project and reproduce the error?

@dimvar I don't work at Google anymore :)

I can show you the code where it's happening though:

/**
 * Gets JSON:API compliant data.
 * @private
 */
lnkd.NpsPlugin.prototype.getJsonApiPostData_ = function() {
  var formData = new FormData(this.form);
  return JSON.stringify(
      new lnkd.NpsPlugin.NpsJsonApiData(
          this.userName || formData.get('user_name'),
          this.userKey,
          formData.get('score'),
          this.productId || formData.get('product_id'),
          formData.get('comments')));
};

@dimvar just tried with the newest versions of the compiler (and library) as well (20170409.0.0). Same warnings.

This is sounding familiar.
I believe I looked into, and thought I fixed, an issue where methods named get were incorrectly removed.

I was thinking of the opposite problem, actually. #2132
@Datamance it would help a lot if you could show the definition of FormData.

@brad4d FormData is a native web api

@Datamance feel free to submit a PR with the missing extern definitions.

I will try ASAP - it's possible I'll be able to fit something in on saturday. You guys will see it when it comes in!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jleyba picture jleyba  路  7Comments

rongjiecomputer picture rongjiecomputer  路  3Comments

joscha picture joscha  路  5Comments

NekR picture NekR  路  3Comments

sam6321 picture sam6321  路  3Comments