You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
getStatusIcon, as written above, does not compile. It gives the following error:
Function lacks ending return statement and return type does not include 'undefined'.
If we remove the <any> cast in the enum, getStatusIcon compiles.
The workaround is, of course, simple: adding a default case / ending return. But that means we lose the compile-time guarantee that if we add a new enum member, we must handle it in getStatusIcon.
The text was updated successfully, but these errors were encountered:
In the template for generating enums, when
DefaultEnumHandling = EnumHandling.String
is set, the string value is cast toany
.This (among other things) removes a small nicety when working with TypeScript enums of literal types (string, number, boolean, null, undefined), namely exhaustiveness checking in switch statements.
There might well be a good reason to do the cast – please enlighten me if that's the case – but I present an example of my problem below.
Example
Consider the C# enum
Which currently generates the following TypeScript enum (with EnumHandling.String)
Now, imagine a function for getting an icon for a
Status
in TypeScriptThe problem
getStatusIcon
, as written above, does not compile. It gives the following error:If we remove the
<any>
cast in the enum,getStatusIcon
compiles.The workaround is, of course, simple: adding a default case / ending return. But that means we lose the compile-time guarantee that if we add a new enum member, we must handle it in
getStatusIcon
.The text was updated successfully, but these errors were encountered: