Skip to content

Object derived from spreading a class instance from within the class body has wrong type information #53252

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
asnaeb opened this issue Mar 14, 2023 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@asnaeb
Copy link

asnaeb commented Mar 14, 2023

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

This happens on any version

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

class A {
    foo = 'bar'
    baz() {
        return {...this}
    }
}

const a = new A()

const obj = a.baz()
obj.baz() // <- No error but: obj.baz is not a function at runtime

const _obj2 = {...a}
obj2.baz() // <- Correct error

πŸ™ Actual behavior

When spreading a class instance to an object from within the class itself, resulting properties are still presenting methods in its signature.

πŸ™‚ Expected behavior

Discarded methods would be removed from the type.

@fatcerberus
Copy link

Not destructuring, but spread. Destructuring is when you do the reverse: const { x, y } = point

@RyanCavanaugh
Copy link
Member

Duplicate #9726 - enumerability is not tracked by the type system

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 14, 2023
@fatcerberus
Copy link

fatcerberus commented Mar 14, 2023

Interesting that the second example works (or rather, doesn't work) as expected, though

@asnaeb asnaeb changed the title Object derived from detructuring a class instance from within the class body has wrong type information Object derived from spreading a class instance from within the class body has wrong type information Mar 14, 2023
@RyanCavanaugh
Copy link
Member

The curse of doing it right some of the time πŸ™‚

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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

4 participants