-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Switch Case not working with String conditions #10802
Comments
In JavaScript (and hence TypeScript), I think this is what you meant: switch (extension) {
case "txt":
case "xml":
return ResourceType.PlainText;
case "bmp":
case "jpg":
case "jpeg":
case "png":
case "tiff":
case "psd":
case "tga":
case "gif":
return ResourceType.Image;
case "mp3":
case "wav":
case "ogg":
case "flac":
case "wma":
case "m4a":
return ResourceType.Audio;
case "bin":
case "dat":
return ResourceType.Binary;
case "ico":
return ResourceType.Icon;
case "rc":
case "resx":
return ResourceType.ResourceScript;
default:
return ResourceType.Unknown;
} |
Also, you shouldn't use let extension: string = "bin"; Also, Gitter, StackOverflow or IRC are better places to ask these sort of general questions. |
Addressed by comments above. |
Ah thanks for letting me know |
Thinking about just banning this outright. It's hard to believe anyone would ever do this on purpose |
This will now be an error |
(Tracking at #10814) |
TypeScript Version: 1.8.34
Code
Expected behavior:
The Switch case will return the correct value based on the condition ex when extension == "bin" ResourceType.Binary should be returned
Actual behavior:
The Default value is always returned
The text was updated successfully, but these errors were encountered: