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
Cannot infer the type of the visitor method parameter if you use the enum value as the property name.
I reported this issue on the github TypeScript repo and was promptly informed that the issue is already fixed in development for the "next" version of TypeScript (currently named v2.7.0-dev).
There are two work-arounds to this:
Explicity declare the type of the parameter.
Use a string literal for the property name.
Example:
enumRGB{R="r",G="g",B="b"}functionrgbIdentity(rgb: RGB): RGB{returnvisitString(rgb).with<RGB>({// ERROR: type of `value` not inferred properly!// Type is implicitly 'any'[RGB.R]: (value)=>{returnvalue;},// Work-around option #1[RGB.G]: (value: RGB.G)=>{returnvalue;},// Work-around option #2"b": (value)=>{returnvalue;}});}
After the new version fo TypeScript is released, add a unit test for this situation.
The text was updated successfully, but these errors were encountered:
There's a commented-out sample file that needs to be uncommented to enable unit testing of this situation (after upgrading TypeScript): tests/compile_samples/pass/enum.enum-props.inferred-param-type.ts
Cannot infer the type of the visitor method parameter if you use the enum value as the property name.
I reported this issue on the github TypeScript repo and was promptly informed that the issue is already fixed in development for the "next" version of TypeScript (currently named v2.7.0-dev).
There are two work-arounds to this:
Example:
After the new version fo TypeScript is released, add a unit test for this situation.
The text was updated successfully, but these errors were encountered: