-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
On Angular we are considering using ES6 computed prototype methods as part of Angular’s component api but we realized that typescript doesn’t allow us to express this in a type-safe way.
I’m wondering if this is a feature that could be added to typescript or if there is a fundamental issue that would prevent typescript from supporting this. Example:
{Component, onInit, OnInit} from ‘angular2/core';
@Component({
selector: 'my-component'
})
class MyComponent implements OnInit {
[onInit](param1, param2){ return something; }
}
Where onInit
is a const string or ES Symbol, and OnInit
is an interface with the signature of the [onInit]
method. onInit
is a an optional life-cycle hook that Angular will call if the component has this property name.
The reason why we find this api style attractive is that it removes the possibility of name-collisions, which means that we are free to add support for more hooks in the future without affecting any existing components.
PS: ES Observables are already using Symbols to define the observable interface, so this feature would allow creation of Observable interface. I expect more libs will want to take advantage of this api style as computed property and Symbol support becomes better.
Related issue: #4653