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
It would be good if we could declare a method as abstract without the requirement to declare the entire class as abstract.
π Motivating Example
Take an example class such as:
classMyClass{protected_id?: string;protected_isVisible?: boolean;id(val?: string): string| this |undefined{if(val===undefined){returnthis._id;}this._id=val;returnthis;}// Similar implementation for isVisible()}
If I have a bunch of accessor functions like id() that follow the same getter/setter behaviour I have to write out each one in concrete code which takes time and wastes bytes across the network when the code gets sent down the pipe.
What I would do in JS is create a synthesize() function that takes the class and the method name and then generates the function at runtime against the underlying prototype, something like:
This is a bit sad given that the JS functionality can significantly reduce the byte-size of the file if the class is large and provides a lot of similar accessor functionality. I realise that this might appear to be an edge-case, but right now, TS makes writing conforming JS of this nature a real burden by either creating concrete classes, or ts-ignoring like it's 1999.
π» Use Cases
What do you want to use this for?
What shortcomings exist with current approaches?
What workarounds are you using in the meantime?
The text was updated successfully, but these errors were encountered:
π Search Terms
abstract methods runtime prototype typesafe synthesized
β Viability Checklist
β Suggestion
It would be good if we could declare a method as abstract without the requirement to declare the entire class as abstract.
π Motivating Example
Take an example class such as:
If I have a bunch of accessor functions like
id()
that follow the same getter/setter behaviour I have to write out each one in concrete code which takes time and wastes bytes across the network when the code gets sent down the pipe.What I would do in JS is create a synthesize() function that takes the class and the method name and then generates the function at runtime against the underlying prototype, something like:
It then becomes trivial to add the desired methods as:
At present, I can "sort of" achieve this by ts-ignoring the abstract methods that I know are going to become available at runtime:
This is a bit sad given that the JS functionality can significantly reduce the byte-size of the file if the class is large and provides a lot of similar accessor functionality. I realise that this might appear to be an edge-case, but right now, TS makes writing conforming JS of this nature a real burden by either creating concrete classes, or ts-ignoring like it's 1999.
π» Use Cases
The text was updated successfully, but these errors were encountered: