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

var __extends as --extends CLI option #7983

Closed
streamich opened this issue Apr 9, 2016 · 5 comments
Closed

var __extends as --extends CLI option #7983

streamich opened this issue Apr 9, 2016 · 5 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@streamich
Copy link

Every time you extend a class in TypeScript this code is appended to the transpiled .js file:

var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};

Here is a possible quick fix to allow developers remove this code and specify a global __extends function for all files. In TypeScript command line tool add an extra parameter --extends that allows to provide the code for the __extends function.

For example:

tsc --extends 'window.myExtends;` hello-world.ts

This would output the __extends function as:

var __extends = window.myExtends;
@DanielRosenwasser
Copy link
Member

We already have a --noEmitHelpers compiler option so that you can define your own __extends function yourself in code. Is there any reason that scenario doesn't suffice?

@streamich
Copy link
Author

@DanielRosenwasser thanks, looks like it does the job. But I'm not sure what exactly that option does, I found in documentation:

Do not generate custom helper functions like __extends in compiled output.

So, I'm not sure what else besides __extends it stops to generate, otherwise it's good.

@DanielRosenwasser
Copy link
Member

That's a good point - it might not be quite as granular as you'd want. But here are all of the helpers TypeScript will currently emit.

They're used for:

  • Class inheritance
  • Decorators & decorator metadata
  • Async functions (i.e. async/await)
  • JSX Spread attributes

In any case, for now I think we'll close this (since the extra emit isn't so bad anyhow), but if it becomes a real issue, we can consider making things more granular.

@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript Declined The issue was declined as something which matches the TypeScript vision labels Apr 9, 2016
@streamich
Copy link
Author

  1. Yes, more granular would indeed be helpful.
  2. What do you exactly mean by JSX Spread attributes? For me in .tsx files it just generates Reacts's React.__spread.
  3. BTW, React.__spread is deprecated now, will it be replaced in the future?

@DanielRosenwasser
Copy link
Member

Check out #7270.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants