Skip to content

Incorrect TS2790 error when removing property of the instance, that is defined in prototype #56763

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
mnaoumov opened this issue Dec 13, 2023 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@mnaoumov
Copy link

mnaoumov commented Dec 13, 2023

πŸ”Ž Search Terms

TS2790

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________

⏯ Playground Link

https://www.typescriptlang.org/play?#code/MYGwhgzhAECyCeBhcVoG8BQ1oDMCuAdsABQCU6W20ATgKYAue1B0ALAEwDclAvhnxmAB7AhHrQAlqPpgitaAF5oBWgHc4SFBDLdh0ydNnBa7RcrUbkkbaV0iIQkLQB0IIQHNiAIilijL-CIyLwAaAz85Z0CSUltBe0cXN08fQzl2KMIY0PCZdMyg2LtRRNcPbwB5ACMAK1pgemd3BgAFaiF6DvgAB1oKnGJfPONSAuyw6rqGptb2zvoevoGh-1HosjiMFcjoszJFAD5oAEZ2AGZihycylO3jMeCwu4CsjcvS5O9njPXSHO+HkV4iVrp8vJN6o1mvQ2h0ur1+oM0iNATkIdNobD5otEc81q8gRgAPRE6AASQIADcwCAJAATaC0ajtajQegQdgAdgAnAAGYmkgAqAAt5EJetRZAyhDhoGBoAByOm0Jz0WgK6DiplgTqsgC2eDE0CqYu69AkIhpzgwytV8meY04QA

πŸ’» Code

class MyClass {
  func() {
    return 42;
  }
}

const instance = new MyClass();
const instance2 = new MyClass();
console.log("instance.func()", instance.func());
console.log("instance2.func()", instance2.func());
console.log("Object.getPrototypeOf(instance).func()", Object.getPrototypeOf(instance).func());

instance.func = () => 123;
console.log("instance.func()", instance.func());
console.log("instance2.func()", instance2.func());
console.log("Object.getPrototypeOf(instance).func()", Object.getPrototypeOf(instance).func());

// Invalid error ts2790
// The operand of a 'delete' operator must be optional.
delete instance.func;

πŸ™ Actual behavior

Error ts2790: The operand of a 'delete' operator must be optional.

It is wrong, because property func is defined in the instance prototype, not the instance itself and we set to the instance manually. Therefore we should be able to remove it to rollback to the prototype behavior

πŸ™‚ Expected behavior

No compiler error and the property is used again from the prototype as before

Additional information about the issue

No response

@fatcerberus
Copy link

The type system doesn't make a distinction between prototype properties and instance properties

@jcalz
Copy link
Contributor

jcalz commented Dec 13, 2023

depends on #51073 --> #9726

also #20922 (comment)

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Dec 13, 2023
@typescript-bot
Copy link
Collaborator

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

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2023
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