TypeScript Version: 2.1.X (Playground)
Code
interfaceI{x: number,y: number,z: ()=>void}classMyClassimplementsI{constructor(publicx: number,publicy: number){}z(){alert(this.x+this.y)}}varx: I=newMyClass(5,7);varo={ ...x}alert(o.z);// undefinedExpected behavior:
Compile error. Either MyClass incorrectly implements I interface requiring to define z as z=()=>alert(this.x + this.y) or at alert(o.z) reporting there is no such a property on o, or report something similar to FlowType.
Actual behavior:
No compiler warnings and runtime error when trying to invoke o.z().
Note:
When I change a definition of I this way: interface I { x: number, y: number, z(): void }, I get an error Property 'z' does not exist on type '{ x: number; y: number; }' as expected.
TypeScript Version: 2.1.X (Playground)
Code
Expected behavior:
Compile error. Either MyClass incorrectly implements
Iinterface requiring to definezasz=()=>alert(this.x + this.y)or atalert(o.z)reporting there is no such a property ono, or report something similar to FlowType.Actual behavior:
No compiler warnings and runtime error when trying to invoke
o.z().Note:
When I change a definition of
Ithis way:interface I { x: number, y: number, z(): void }, I get an errorProperty 'z' does not exist on type '{ x: number; y: number; }'as expected.