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
I'm having trouble explaining this in words so perhaps we'll just jump straight into the code.
// The enum that was generated from the server codedeclare module server{enumRuleType{All=0,Required=1,RequiredChoice=2,EnableDisable=3,EnableDisableChoice=4,ShowHide=5,ShowHideChoice=6,AutoSet=7,DependencySetup=8,}}// Some data that we may have retreived from the servervartheItem={value:1,name: 'Required'};// This example works because the reference to the enum is replaced with it's valueif(theItem.value===server.RuleType.Required){alert('Required checked by enum ID!');}// This example does not work because server.RuleType is undefinedif(theItem.name===server.RuleType[server.RuleType.Required]){alert('Required checked by enum Name!');}
At first I thought this was a problem with Web Essentials but I realized now that this would be better to fix in the TypeScript compiler since it already replaces the enum value, why not the name too?
Here is a working example if you want to see the compiled output.
The text was updated successfully, but these errors were encountered:
You'd also need to move the enum declaration into a .ts file instead of a d.tsfile.
declare is for declaring things which exist at runtime. The compiler assumes that if you say declare var x; there's actually going to be something called x. The same applies for enums.
I'm having trouble explaining this in words so perhaps we'll just jump straight into the code.
At first I thought this was a problem with Web Essentials but I realized now that this would be better to fix in the TypeScript compiler since it already replaces the enum value, why not the name too?
Here is a working example if you want to see the compiled output.
The text was updated successfully, but these errors were encountered: