Description
TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx)
Code
interface AllMembersOptional {
first?: string;
second?: number;
}
let a: AllMembersOptional = 7;
let b: AllMembersOptional = () => 7;
Expected behavior:
compiler error '7' is not type AllMembersOptional -- let a: AllMembersOptional = 7;
compiler error 'function: number' is not type AllMembersOptional -- let b: AllMembersOptional = () => 7;
Actual behavior:
no compiler errors or warnings and the following javascript is generated:
var a = 7;
var b = function () { return 7; };
Actual example
Referencing angular.d.ts and converting an angular directive
angular.module('test').directive('custom', function () {
return {
controller: 'testCtrl',
template: '<div></div>,
//...
};
});
carelessly into a component
angular.module('test').component('custom', function () {
return {
controller: 'testCtrl',
template: '<div></div>,
//...
};
});
generates no typescript compiler error messages and will fail at run-time because the options parameter needs to be an object
angular.module('test').component('custom', {
controller: 'testCtrl',
template: '<div></div>,
//...
}
);
options parameter cannot a function (or number or string etc).
Just about anything passed in for a parameter of an interface type with all optional parameters will be allowed by typescript