Interfaces in Typescript strictly do not have value, as they are entities that only exist for type-checking and are not compiled into JS.
You can't define a decorator in an interface because the decorator has value. It's a function that takes an argument and gives value to the class property, and not a type.
Angular's @Input decorators themselves do have a typing, but it's impossible to type them in a lower-order class since that property is itself already a type, but given value by the decorator:
export interface ITest {
prop: Input;
prop2: InputDecorator;
}
export class Test implements ITest {
@Input('thing') prop: string;
@Input('thing2') prop2: string;
}
// typeerror: Test does not correctly implement ITest
However, component classes can be derived from in Angular, and the parent class' decorators will be inherited by the child. This is useful if you want to implement strong typing alongside a more polymorphic approach to your code:
export class NumberBase {
@Input('number') number: number;
}
export class NumberComponent extends NumberBase {
ngOnInit() {
console.log(this.number); // works!
}
}
Components can extend either plain TS classes or fully decorated Angular components.
NumberComponent implements NumberInterfaceisn't a thing in Angular. Despite the name, it's not a class interface, but simply a collection of types.