Extending class 'extends' to work with expressions #239
Labels
Duplicate
An existing issue was already created
Needs Proposal
This issue needs a plan that clarifies the finer details of how it could be implemented.
Suggestion
An idea for TypeScript
Example
Codegen
Should be able to unpack the class expressions and codegen as we do now. We can pass the resulting expression as the parameter to the codegen’d constructor function as we do already.
Typecheck
The type of the expression follows the same rules we have for class declarations now. The expressions create constructor functions as before.
In the extends position, e.g. "class A extends B", the extends clause must be an expression, or a Generic NamedTypeReference. If it is an expression, the extends clause uses the type of the expression. This type must have a constructor signature.
This would allow it to be compatible with the current system and be more flexible with arbitrary expressions, as we would treat class name TypeReferences as constructor functions we will get the type of.
Questions
Traceur says it’s not in scope outside of B’s expression. Looks like we may be able to translate the expressions in-place as a call to the constructor function
We require all overloads to return the same type
We would disallow generic constructor signatures. These can’t arise as the type of a signature of a class’s constructor, so we’d follow a similar restriction.
Needs answer
We would need to tweaking the parsing precedence to ensure the correct parse is checked first.
The text was updated successfully, but these errors were encountered: