Closed
Description
Bug Report
β― Playground Link
Playground link with relevant code
π» Code
class Test{get Length(){return 1;}}
function spread<T> (t: T) { return {... t} }
let test1 = {...new Test()};
console.log(test1.Length); // Expected: throws error. Actual: throws error.
let test2 = (o => ({...o}))(new Test());
console.log(test2.Length); // Expected: throws error. Actual: throws error.
let test3 = spread(new Test());
console.log(test3.Length); // Expected: throws error. Actual: doesn't throw error.
π Actual behavior
Doesn't throw compile-time error.
Error is at runtime, the spread operator of Test does not copy over properties.
π Expected behavior
Typescript's type system should figure out that the type is not T but instead is just enumerable properties of T.