google / google/closure-compiler
Compiler should warn when deleting a property that can't be undefined
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
[repro]
The compiler already warns when you try to set such a property to `undefined`, but `delete`ing it circumvents this warning:
```js
const /** {x: number, y: number} */ point = {x: 1, y:2};
point.x = null; // Compiler does warn
point.x = undefined; // Compiler does warn
delete point.x; // Compiler does not warn
```
```
input0:3: WARNING - assignment to property x of point
found : null
required: number
point.x = null; // Compiler does warn
^^^^^^^^^^^^^^
input0:4: WARNING - assignment to property x of point
found : undefined
required: number
point.x = undefined; // Compiler does warn
^^^^^^^^^^^^^^^^^^^
```
[repro]: https://closure-compiler-debugger.appspot.com/#input0%3Dconst%2520%252F**%2520%257Bx%253A%2520number%252C%2520y%253A%2520number%257D%2520*%252F%2520point%2520%253D%2520%257Bx%253A%25201%252C%2520y%253A2%257D%253B%250A%250Apoint.x%2520%253D%2520null%253B%2520%2520%252F%252F%2520Compiler%2520does%2520warn%250Apoint.x%2520%253D%2520undefined%253B%2520%2520%252F%252F%2520Compiler%2520does%2520warn%250Adelete%2520point.x%253B%2520%2520%252F%252F%2520Compiler%2520does%2520not%2520warn%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3Dtrue%26CHECK_SYMBOLS%3Dtrue%26MISSING_PROPERTIES%3Dtrue%26TRANSPILE%3Dtrue%26CHECK_TYPES%3Dtrue%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue
Contributor guide
Assessment
This issue has not been assessed yet.