Skip to content

emit _classCallCheck #6569

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
basarat opened this issue Jan 22, 2016 · 3 comments
Closed

emit _classCallCheck #6569

basarat opened this issue Jan 22, 2016 · 3 comments
Labels
Revisit An issue worth coming back to Suggestion An idea for TypeScript

Comments

@basarat
Copy link
Contributor

basarat commented Jan 22, 2016

For the follwing:

class Foo{ 
}

Babel emits:

"use strict";

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Foo = function Foo() {
  _classCallCheck(this, Foo);
};

Not really needed for TypeScript. But a request for a similar emit was made for TypeScript : http://stackoverflow.com/q/34945858/390330

Purely for tracking 🌹

@mrsimonemms
Copy link

As the author of the SO post, my use-case is for times when writing a library that may or may not be consumed by TypeScript. Clearly, this should be off by default, but it would be useful to be able to throw a runtime error if the function wasn't called with new (as in Babel).

It would also be useful to have this flag throw runtime errors for as many of the TypeScript compiler errors as is practical (checking that an object fulfils an interface is probably impossible, but checking that the input is an object is achievable).

@DanielRosenwasser DanielRosenwasser added the Suggestion An idea for TypeScript label Jan 22, 2016
@mhegazy mhegazy added the Revisit An issue worth coming back to label Feb 19, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Feb 19, 2016

with #5595 in place, such transformations should be easy to do as extensions to the compiler. marking this as revisit for now.

@RyanCavanaugh
Copy link
Member

Closing due to lack of additional feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Revisit An issue worth coming back to Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants