Skip to content

Function returning spread operator infers wrong type and get properties can be accessed #44543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
michaelcheers opened this issue Jun 10, 2021 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@michaelcheers
Copy link

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.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 10, 2021
@RyanCavanaugh
Copy link
Member

See #9726

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants