Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: closure compiler externs problem. #661

Closed
martin19 opened this issue Nov 27, 2017 · 3 comments
Closed

Question: closure compiler externs problem. #661

martin19 opened this issue Nov 27, 2017 · 3 comments

Comments

@martin19
Copy link

I'm trying to get rolling with generating externs for google closure compiler with tsickle.
Here is my setup.

main.ts

import Bar = require("externalmodule");
console.log(Bar.Foo.EPSILON);

foo.d.ts

declare module 'externalmodule' {
   export class Foo {
     public static EPSILON: number;
  }
}

The following files are generated.

main.js

goog.module('src.main');var module = module || {id: 'src/main.js'};
/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes} checked by tsc
 */

var Bar = goog.require('externalmodule');
console.log(Bar.Foo.EPSILON);

extern.js

/**
 * @externs
 * @suppress {duplicate,checkTypes}
 */
// NOTE: generated by tsickle, do not edit.
// externs from src/test.d.ts:
/** @const */
var tsickle_declare_module = {};
// Derived from: declare module "externalmodule"
/** @const */
tsickle_declare_module.externalmodule = {};
/**
 * @constructor
 * @struct
 */
tsickle_declare_module.externalmodule.Foo = function() {};
 /** @type {number} */
tsickle_declare_module.externalmodule.Foo.EPSILON;

closure compiler outputs:

grunt
Running "closure-compiler:build" (closure-compiler) task
Warning: Command failed: java -jar "./closure-compiler/build/compiler.jar" --js "src/extern.js" --js "src/foo.js" --js "src/main.js" --js_output_file "C:\Users\marti\tsi
ckle\test/dist/lib/output.min.js" --externs externs/extern.js --compilation_level "ADVANCED_OPTIMIZATIONS" --language_in "ECMASCRIPT6_STRICT"
src/main.js:7: ERROR - Required namespace "externalmodule" never defined.
var Bar = goog.require('externalmodule');
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 error(s), 0 warning(s)
 Use --force to continue.

What is the problem here?

@martin19 martin19 changed the title closure compiler externs problem. Question: closure compiler externs problem. Nov 27, 2017
@mprobst
Copy link
Contributor

mprobst commented Nov 28, 2017 via email

@martin19
Copy link
Author

martin19 commented Dec 1, 2017

Thank you for the help.

After some days of tsickling...

  • removing circular dependencies from ts code
  • removing jsdoc
  • removing "module" and "namespace" declarations
  • moving enums to separate files and use "export" after enum definition (only works like that)
  • postprocessing tsickle output to lowercase all goog.module, goog.require, goog.forwardDeclare names
    because casing of the output is incomprehensibly wrong.

...I've found out (closure output):

  • webgl2externs for closure compiler are not available yet
  • ES6 transpilation of 'assigning to a super property' is not yet implemented.

And I'm left with:

0 error(s), 3057 warning(s), 71.9% typed
and 52kb output file that doesn't do anything.

I'm a bit disillusioned. Even if the readme has warned about that.

@evmar
Copy link
Contributor

evmar commented Sep 17, 2019

Gonna fold this into the general "externs are a mess" #1041

@evmar evmar closed this as completed Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants