opencascade.js
opencascade.js copied to clipboard
Fix typescript definitions for enums
The following valid code
const quat = new oc.gp_Quaternion_1();
quat.SetEulerAngles(oc.gp_EulerSequence.gp_Extrinsic_XYZ, 0, 0, 0));
results in a typescript error:
(property) gp_Extrinsic_XYZ: {}
Argument of type '{}' is not assignable to parameter of type 'gp_EulerSequence'.
Type '{}' is missing the following properties from type 'gp_EulerSequence': gp_EulerAngles, gp_YawPitchRoll, gp_Extrinsic_XYZ, gp_Extrinsic_XZY, and 22 more.ts(2345)
The previous syntax in the "valid code" was incorrect. Instead, this should be:
const quat = new oc.gp_Quaternion_1();
quat.SetEulerAngles(oc.gp_EulerSequence.gp_Extrinsic_XYZ.value, 0, 0, 0));
It's tricky to figure this out, since Emscripten doesn't seem to error. Another example:
The following code causes no typescript error and no runtime error. It is however, incorrect.
myContext.SetDisplayMode_1(oc.AIS_DisplayMode.AIS_Shaded, true);
console.log(myContext.DisplayMode()); // outputs '0', should be '1'
The following code causes a typescript error, but works correctly at runtime
myContext.SetDisplayMode_1(oc.AIS_DisplayMode.AIS_Shaded.value, true);
console.log(myContext.DisplayMode()); // outputs '1'