Skip to content

Unable to extend classes which constructors require new when targeting es5 #11304

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

Closed
falsandtru opened this issue Oct 2, 2016 · 6 comments
Closed
Labels
Suggestion An idea for TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it

Comments

@falsandtru
Copy link
Contributor

TypeScript Version: master

Code

new class extends Map {}();

Expected behavior:

$ node built/local/tsc.js -t es5 --lib es6 index.ts && node index.js

Actual behavior:

$ node built/local/tsc.js -t es5 --lib es6 index.ts && node index.js
...\index.js:9
        return _super.apply(this, arguments) || this;
                      ^

TypeError: Constructor Map requires 'new'
@falsandtru falsandtru changed the title Unable to extend classes which require new when targeting es5 Unable to extend classes which constructors require new when targeting es5 Oct 2, 2016
@DanielRosenwasser
Copy link
Member

I'll note that this doesn't work in 2.0 or in Babel either.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Oct 2, 2016
@falsandtru
Copy link
Contributor Author

Hm, seems like there is no way to fix this bug. I think, so new.target is added in es6.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Oct 2, 2016

I think super calls could potentially be emitted as

_this = new (Function.prototype.bind.apply(_super, [null].concat(arguments)))

but I think that would have a pretty bad performance impact.

@falsandtru
Copy link
Contributor Author

Then can you make _this as an instance of both base and derived classes for instanceof operator?

@mhegazy mhegazy added Suggestion An idea for TypeScript ES6 Relates to the ES6 Spec and removed Bug A bug in TypeScript labels Dec 7, 2016
Terseus added a commit to Terseus/typed-ip that referenced this issue Nov 1, 2017
We were hit by this issue:
microsoft/TypeScript#11304

Until it's fixed, `AddressBuffer` functionality has been replaced
entirely with standalone functions.
It was very poor named anyway...
@ghost
Copy link

ghost commented Aug 14, 2018

See also #10853 which is closed, even though the issue is not resolved.

@RyanCavanaugh RyanCavanaugh added Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it and removed Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. ES6 Relates to the ES6 Spec labels Feb 23, 2024
@RyanCavanaugh
Copy link
Member

This doesn't seem like an important scenario for modern JS development - folks can either target ES6, or use an alternate transpiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Suggestion An idea for TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Projects
None yet
Development

No branches or pull requests

4 participants