Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed code doesn't work during runtime #6

Open
Nodonisko opened this issue Jan 5, 2025 · 1 comment
Open

Typed code doesn't work during runtime #6

Nodonisko opened this issue Jan 5, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@Nodonisko
Copy link

Nodonisko commented Jan 5, 2025

Problem

I was able to hack build enough to get some typed coded into app, but it fails during runtime, even simple expressions like var num: number = 42; will throw syntax error.

I am not sure what's wrong, does Static Hermes need some additional config/flags to be able to process TS code during runtime? And how can I even tell that I am running Static Hermes and not normal Hermes? Are there any internals that I can log to see if it's correct version?

Solution

Additional Context

@Nodonisko Nodonisko added the enhancement New feature or request label Jan 5, 2025
@Nodonisko Nodonisko changed the title How to get typed code into Static Hermes How to get typed code into Static Hermes for single file Jan 5, 2025
@Nodonisko Nodonisko changed the title How to get typed code into Static Hermes for single file Typed code doesn't work during runtime Jan 5, 2025
@Nodonisko
Copy link
Author

Nodonisko commented Jan 9, 2025

So update on my progress here (iOS only):

  1. As I expected you need to pass -typed arg to process starting Static Hermes in file node_modules/react-native/scripts/react-native-xcode.sh around line ~176 or use $EXTRA_COMPILER_ARGS="-typed" env variable in .xcode.env

  2. Second issue was build pipeline which of course strips all types using Babel. I managed to create solution where I used Metro custom transformer option to transform some files (for example with .shermes.ts suffix) differently. I used modular nature of Typescript compiler and some of it's internal function to transform code in this files to CommonJS and ES6 (which should work in RN) but also to keep types in source code. This was very hacky-glued solution but it produced code that looked okay with preserved types 🎉

But sadly that was my last win, even that I was able to get some typed code into Static Hermes compiler I started getting lot of Segmentation fault errors. Lot of them was in React source code or in React Native Fabric JS part of code. I fixed quite a big amount of them. Sometimes it was like changing null === a to a === null etc. but there were too many of them and it was clearly not good direction.

In the end I removed all my experimental typed code and tried to compile untyped code of just RN and sadly that is not possible too when Hermes -typed mode is enabled 😢

I am not giving up yet. One idea that I have, is to somehow convince Static Hermes to compile in -typed mode only some functions that are annotated with some comment for example. But to be fair I am not familiar with internals of Hermes at all and also not much proficient with C++ so maybe this will be impossible due to architecture of Hermes, but IDK. Would be nice if someone with more experience with Static Hermes can tell me if this is even worth exploring or it's totally waste of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant