DEV Community 👩‍💻👨‍💻

Cover image for Why React Native TypeScript config recommends to use a five years old standard (lib: es2017)?
David Narbutovich
David Narbutovich

Posted on

Why React Native TypeScript config recommends to use a five years old standard (lib: es2017)?

Have you ever read official guide of using Typescript in React Native. Did you mention something strange in tsconfig.json ?

"lib": ["es2017"] lib option looks weird, 5 year old standard recommended as default, isn't it?

If you wants to use some modern methods:

  • [].flat(...)
  • [].flatMap(...)
  • Object.fromEntries({ })
  • 'str'.trimEnd() ...

Typescript will politely throw an error:

Object.fromEntries(...)
//     ^^^^^^^^^^ TS2550: Property 'fromEntries' does not exist on type 'ObjectConstructor'. 
//                Do you need to change your target library? 
//                Try changing the 'lib' compiler option to 'es2019' or later.
Enter fullscreen mode Exit fullscreen mode

But, wait when I run this code on simulator iOS & Android I didn't get any runtime errors.

So, is it mean that documentation is outdated?

Actually no, everything depends on JavaScript engine that will run your code

By default React Native use:

Note: Also, include some polyfills for many standard functions

P.S. For me, that was a surprised that Promise is polyfilled too :(

For example, if you try to use Array.prototype.flat() your app will crash for users who using iOS 11. Yes this one reason why es2017

And iOS 11 is a minimal supported version by React Native (till 0.68.x)

but starting from React Native 0.69.0 iOS 12.4 is minimal supported version (thanks Meta!)


Great thing that you haven't ever need to looking for information about JavaScript modern features and Engines that support them.

Now it is easier to compare Typescript lib options \ JS features and JS Engines

react native compat table


Anyway, Meta also developing their own Javascript Engine Hermes that tried to align all new EcmaScript specifications


Even more, you can use V8 JavaScript Engine

react-native-v8 has the greatest support for all modern JS features.

You can comprate all JavaScript Engines compatibility table and verify you tsconfig, if if it use a right lib option!


Useful links links:

Top comments (0)

🌚 Life is too short to browse without dark mode