Cannot access ambient const enums (when using create react app)

I am trying to import an enum ‘XRHandJoint’, but I get a compilation error ‘Cannot access ambient const enums when the ‘–isolatedModules’ flag is provided’.

I think this post explains the problem TypeScript: Don’t Export const enums — @ncjamieson

I wanted to ask if anybody has any suggestions? setting the isolatedModules flag to false won’t help here. So for now, I am copying the XRHandJoint enum into my own module and adding // @ts-ignore everywhere the enum is needed in my code.

cc @RaananW

XRHandJoint is part of the webxr specifications, and is (as you found out :-)) an enum, as defined here -

XRHandJoint

You don’t need to import it, you should be able to use it directly, as the webxr.d.ts should be a part of your project. if it isn’t, you need to add @types/webxr to your project. It should be updated.

As it is a const-enum, upon compilation it will change the values in your compiled js.

Thanks RaannaW,
I think I might be missing something here. @types/webxr does not have any declaration for the XRHandJoint.

The problem with using export const enum instead of just export enum is still there for other enums such as HandPart, so I can’t use ‘getHandPartMeshes()’, unless I copy the enum declaration.

I’ll make sure that the webxr def includes this in its next version. Babylon does provide its own webxr declaration file where everything we user is defined correctly.

On our side, i have no issue with changing the const enum to enum. TBH we usually don’t use const enum, I’m not too sure how this one slipped by. I’ll change it soon.

Thanks that would be great. I hope changing const enum to enum won’t have any major impact on performance.

Thanks again for the quick response.

[XR] switch to enum (instead of const-enum) by RaananW · Pull Request #12517 · BabylonJS/Babylon.js (github.com)