google / google/closure-compiler
Better typechecking for enums in switch/case statements.
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
If the thing passed to a `switch` is not the same type as the `case`s we should perhaps warn about that. Example:
https://closure-compiler-debugger.appspot.com/#input0%3D%252F**%2520%2540enum%2520%257Bstring%257D%2520*%252F%250Avar%2520Color%2520%253D%2520%257B%250A%2520%2520RED%253A%2520'red'%252C%250A%2520%2520ORANGE%253A%2520'orange'%250A%257D%253B%250A%250A%252F**%2520%2540enum%2520%257Bstring%257D%2520*%252F%250Avar%2520Shape%2520%253D%2520%257B%250A%2520%2520SQUARE%253A%2520'square'%252C%250A%2520%2520TRIANGLE%253A%2520'triangle'%250A%257D%253B%250A%250A%252F**%2520%2540param%2520%257BShape%257D%2520shape%2520*%252F%250Afunction%2520f(shape)%2520%257B%250A%2520%2520switch%2520(shape)%2520%257B%250A%2520%2520%2520%2520case%2520Color.RED%253A%250A%2520%2520%2520%2520%2520%2520alert('r')%253B%250A%2520%2520%2520%2520case%2520Color.ORANGE%253A%250A%2520%2520%2520%2520%2520%2520alert('o')%253B%250A%2520%2520%257D%250A%257D%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26MISSING_PROPERTIES%3D1
A shape will never be a color so we should warn about this.
Contributor guide
Assessment
This issue has not been assessed yet.