Skip to content
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

TypeScript infer wrongly copying 'this' #34878

Closed
maciejsikora opened this issue Nov 2, 2019 · 3 comments
Closed

TypeScript infer wrongly copying 'this' #34878

maciejsikora opened this issue Nov 2, 2019 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@maciejsikora
Copy link

TypeScript Version: 3.7-Beta

Search Terms: copy this, spread this

Code

class A {
  method1() {
     return 'method1'
  }
  copy() {
    return { ...this };
  }
}
const a = new A();
a.copy().method1(); // runtime error

Expected behavior:
Return of a.copy() should not consider having prototype methods.

Actual behavior:
Return of a.copy() has a type this

@DanielRosenwasser DanielRosenwasser added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Nov 2, 2019
@DanielRosenwasser
Copy link
Member

Initially thought the bug was the runtime behavior and not the type. I thought that generally speaking, method-declared values weren't included on spreads @sandersn.

@fatcerberus
Copy link

I thought that generally speaking, method-declared values weren't included on spreads

No, they definitely are. See e.g.

And probably some others.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 8, 2019
@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

5 participants