Support for Reflect.getMetadata() in a published Expo app

Just a quick sanity check.

Should I expect react-native to work correctly with Typescript decorators, specifically Reflect.getMetadata? I’ve enabled emitDecoratorMetadata and experimentalDecorators along with react-native-typescript-transformer.

To add a bit to this, a non-published expo app works with this (and I see the transpiled code emitted correctly), but not once published. Specifically, my decorator implementation is executed but Reflect.getMetadata always returns null in a published app.

I know the tooling here is pretty specific, but think its worth a shot to ask.

Hi @cantide5ga.

I’m not that familiar with Typescript so don’t have a great answer for this specific issue. One thing that might help is running exp with exp start --minify --no-dev. That’ll let you load the bundle as if it was a published bundle. My guess would be that something with minify is breaking it. Maybe that’ll make it easier to debug.

Excellent suggestion. I’ve cross posted this question in a few other places as well, but will keep this in parity when I figure things out.

Really appreciate it.

1 Like

For some reason (maybe timing), debugging of any sort gets me a null return from the return of Reflect.getMetadata(). Digging into the object despite this, I get some good stuff - including the mangling done by minification that @jesse was alluding to.

The second issue is consequence of the first - my implementation was relying too much on the handle of the class type of the decorated property that changed when bundled. So that’s why it blew up.

I changed my implementation to work off of signatures that were spared minification (in this case, the property name). Guess I didn’t dig enough into the bundling done here, so learned some good stuff.

Thanks @jesse!

That being said, I’m afraid I’m relying too much on an implementation detail as I usually see variable names minified as well. Do you have any suggestions on configuring what is minified?

I believe RN uses uglify-js for minification. The library might allow you to configure how these different elements are minified, but I don’t think Metro (the bundler RN’s tools use) exposes a configuration interface for it. Possibly worth looking into though!

Yup, not Expo’s problem. Thanks for all the tips!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.