-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Double error on invalid delete of readonly property #53082
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
Comments
Hi, I wanted to work on this where should I start. |
Hey ! I have possible explanation for the second error. Error : The operand of a 'delete' operator must be optional. Explanation : That was a false positive where the prototype chain still includes the property - bcoz the delete statement only works on direct properties, and not on inherited properties. This got corrected in the later versions of typescript. One possible fix : declare 'name' member inside class as optional. |
This bug doesn't seem to reproduce in a compiler or fourslash test, so this looks to be something in the services causing a duplicate error to occur (not uncommon). In particular, the @ahmad2901 Likely, this needs a test like in #52696 or #52373 which baselines the old bad behavior, followed by a change which fixes the bug and changes the baseline to only contain one error. @Bismay5467 I don't think that's related, given it doesn't reproduce in a compiler test, only in the editor, and this bug is about that inconsistency. |
Hey, @jakebailey I am new to typescript can you recommend where should I get started? |
The place to start would be to find all places in the checker which emit this error message, set a breakpoint at each, and figure out in which conditions both appear, and see which one shouldn't be happening. |
sure thanks for your help. |
@jakebailey by checker do you mean tests folder?? |
@jakebailey i can't repro on 5.0.2 and 4.0 - i get the second error even when running the fix looks like it'd be simple to me so i'm likely just misunderstanding something here if (isReadonlySymbol(symbol)) {
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
// missing return, so tsc *may* emit a second error from the below function call
}
checkDeleteExpressionMustBeOptional(expr, symbol); |
Hey @jakebailey , any updates on this issue? I am unable to replicate this issue. I have tried versions 3.0, 3.9, 4.0 and 4.9 and there was a single error for all of them
|
I don't have any updates. This only reproduces in the language service and the playground, as I said before. If you check the latter by the link in my issue, you'll see it says there are two errors on the right. |
This is my first time contributing to an open-source project, I would really appreciate your help. I have cloned the repo and switched to the release-4.0 branch then I ran these commands
Then I created a test.ts file with the code mentioned in the issue then to run that file I used this command
Output:
I am actively looking for issues where I can contribute, please feel free to recommend any other issues/bugs or study material that can help me |
What are the errors? Can you be more specific? |
@gooddavvy check the "Playground Link" heading in the original post |
I think to it's trying to get an operand which could be empty, a property which has no use but still exist in the object. |
Is this issue fixed, or could I work on it? |
There is #53961 which presumably fixes the issue but isn't yet complete. Also note: https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md#issue-claiming |
Bug Report
π Search Terms
operand delete operator double diagnostic error
π Version & Regression Information
Before 4.0, we only gave one error here. In 4.0 and above, we give two errors.
β― Playground Link
Playground Link
π» Code
π Actual behavior
Two errors
π Expected behavior
One error
The text was updated successfully, but these errors were encountered: