You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var obj = new (class { x = 5; });
var cls = class { x = 5; };
var cls2 = class extends cls { y = 6; };
var obj2 = new cls2();
// and so on
Sadly, this support is absent in the current TypeScript compiler (I'm using the 9.2 branch) - that is, the above examples would not compile.
Aside from TS team's own argument of "closely aligning with the ES6 specification", this support would enable many useful scenarios for which I currently have to fall back to "any-typed" plain JavaScript.
Here are a few examples of such scenarios which I actually use in my daily work:
Returning a class (not object) from a function. With TypeScript, it is currently possible to describe the return type of such function, but not to actually write its body using the "class" construct.
"Bind" a class - similar to "binding" a function, i.e. produce another class with certain constructor parameters bound to specific values.
Declare a "private" class within the body of a function or within another class.
The text was updated successfully, but these errors were encountered:
The ES6 definition of the "class" construct has the concept of "class expression" - i.e. class definitions may be used as values, such as:
Sadly, this support is absent in the current TypeScript compiler (I'm using the 9.2 branch) - that is, the above examples would not compile.
Aside from TS team's own argument of "closely aligning with the ES6 specification", this support would enable many useful scenarios for which I currently have to fall back to "any-typed" plain JavaScript.
Here are a few examples of such scenarios which I actually use in my daily work:
The text was updated successfully, but these errors were encountered: