I am interested in implementing a rule that mandates certain members of a typescript
interface to have decorators in their implementation.
Below is an example of the interface I have:
export interface InjectComponentDef<TComponent> {
// TODO: How can I restrict this to only allow properties decorated with @Input()
inputs: Partial<TComponent>, // & { @Input() [key: string]: any } my attempt to enforce decorator, invalid syntax
//...
};
In the following class example, I aim to prevent the inclusion of the notAnInput
property in an InjectComponentDef.inputs
implementation:
export class MyComponent {
public @Input() isAnInput: string;
public notAnInput: string;
}
...
let x: InputComponentDef<MyComponent> =
{
inputs: {
isAnInput:'all good',
notAnInput:'no good', // I want this to throw a compile time error because it is not decorated with @Input
}
}
Is there a way to achieve this in typescript at compile time?