I was to create a TypeScript interface that not only requires that particular attributes are present, but also prohibits attributes that are not part of the definition. Here is an example:
export interface IComponentDirective {
scope : any;
templateUrl : string;
};
var ddo : IComponentDirective = {
scope: {
dt: '='
},
templateUrl: 'directives.datepicker',
controller: function() {
console.log('hello world');
}
};
Even though controller
is not defined in the interface, the ddo
assignment doesn't throw an error. Doing some research, this looks like it might be as designed:
Notice that our object actually has more properties than this, but the compiler only checks to that at least the ones required are present and match the types required.
Notice, however, that after I declare ddo
as a IComponentDirective
, if I try something like:
ddo.transclude = false;
The transpiler will complain with:
2339 Property 'transclude' does not exist on type 'IComponentDirective'.
Is there any way to enforce a tighter contract?