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

  • Home
  • SEARCH
  • 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 8918681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:48:56+00:00 2026-06-15T05:48:56+00:00

I use Typescript command (tsc) to create a single Javascript file containing all plateform

  • 0

I use Typescript command (tsc) to create a single Javascript file containing all plateform classes.

tsc "./Main.ts" -out "./script/myProject_debug.js" --declarations

Then, I want to obfuscate this file with Google Closure (compiler.jar) like this :

java -jar ./compiler/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js "./script/myProject_debug.js" > "./script/myProject.js".

But when I execute the resulting obfuscated/optimized code, I got this following error : Uncaught TypeError: Cannot read property ‘prototype’ of undefined

Which matches the following non-obfuscated JS code (generated by tsc command) :

var __extends = this.__extends || function (d, b) {
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
}

This part is used to translate the “extends” Typescript keyword and the equivalent of b is undefined.

Is anyone got similar error or/and get a solution to be able to obfuscate with Google Closure with a Typescript compiled file?

I tried with uglifyjs command and the output file works perfectly, but I want total obfuscation (classes, args, variables, methods, etc). Also, the extra optimization provided by Google Closure would be welcome.

Thanks you!

  • 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-15T05:48:57+00:00Added an answer on June 15, 2026 at 5:48 am

    Ok I found the problem.

    As I said earlier, b is undefined in :

    var __extends = this.__extends || function (d, b) {
       function __() { this.constructor = d; }
       __.prototype = b.prototype;
       d.prototype = new __();
    }
    

    When typescript “compile” into javascript, if you got one namespace by project but that you write all classes related to this namespace in separated files, Typescript do the following in the final generated js file :

    var namespace;
    (function (namespace) {
    
        var Class1 = (function (dependency) {
            [...]
            return Class1;
        })(namespace.dependency);
    
        namespace.Class1 = Class1;
    })(namespace || (namespace= {}));
    
    var namespace;
    (function (namespace) {
    
        var Class2 = (function (dependency) {
            [...]
            return Class2;
        })(namespace.dependency);
    
        namespace.Class2 = Class2;
    })(namespace || (namespace= {}));
    
    var namespace;
    (function (namespace) {
    
        var Main = (function (dependency) {
            [...]
            return Main;
        })(namespace.Class2);
    
        namespace.Main = Main;
    })(namespace || (namespace= {}));
    

    I don’t know exactly how its works but somewhere google-closure-compiler removed some classes even if there is no problem with this code and JS can handle it. So some dependencies was missing and b was undefined.

    So I found that if you declare your namespace like the following, you will not encounter the error anymore (closure will keep all your classes in the final obfuscated js file as long as the “Main” class is used or that you keep a reference of your namespace in the global window object) :

    var namespace;
    (function (namespace) {
    
        var Class1 = (function (dependency) {
            [...]
            return Class1;
        })(namespace.dependency);
    
        namespace.Class1= Class1;
    
        var Class2 = (function (dependency) {
            [...]
            return Class2;
        })(namespace.dependency);
    
        namespace.Class2= Class2;
    
        var Main = (function (dependency) {
            [...]
            return Main;
        })(namespace.Class2);
    
        namespace.Main = Main;
    })(namespace || (namespace= {}));
    

    I think I will open an issue on typescriptlang.org. It’s optimizing the generated file size by the way.

    Thank you for your answers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use JavaScript libraries in TypeScript? For example I want to
I am trying to use script command for logging a bash session. The script
use grep command to find txt files containing telephone number. telephone number format could
How would I use TypeScript in a Windows 8 Store app that's JavaScript-based? I
I have just downloaded the TypeScript documentation. I have a some JavaScript classes and
I have a simple TypeScript (ts) which needs a function from a JavaScript file.
use C#,want to upload excel file on google doc. bellow syntax use to upload
I am trying to use TypeScript in a Windows 8 app (html5/JS) I have
I'm wondering is there any way to use TypeScript on Razor cshtml files? For
I am trying to create a .d.ts file for the KineticJS library. So far

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.