facebook / react-native-website

The React Native website and docs
https://reactnative.dev
MIT License
1.95k stars 4.37k forks source link

React Native 69 will use iOS 12.4 as minimal version but we still recommends es2017 in TS config #3167

Closed retyui closed 1 year ago

retyui commented 2 years ago

Description

Can we recommend a "lib": ["es2019"] for react-native@0.69.x and above in tsconfig.json ?

What is the problem?

We still recommend to use es2017 for ts config, but with a new minimal iOS version requirements (12.4)

// iOS 11
Intl.PluralRules // undefined (es2018.intl)
Symbol.asyncIterator // undefined (es2018.asynciterable)
String.prototype.trimStart // undefined (es2019.string)
String.prototype.trimEnd // undefined (es2019.string)
Object.fromEntries // undefined (es2019.object)
Array.prototype.flat // undefined (es2019.array)
Array.prototype.flatMap // undefined (es2019.array)

// iOS 12.4
Intl.PluralRules // function
Symbol.asyncIterator // Symbol(Symbol.asyncIterator)
String.prototype.trimStart // function
String.prototype.trimEnd // function
Object.fromEntries // function
Array.prototype.flat // function
Array.prototype.flatMap // function

Links

How can we address it?


Why is it important?

Users will be sure that it's safety to use modern JavaScript features and it won't cause crash in runtime

Who needs this?

TypeScript users

When should this happen (use version numbers if needed)?

React Native 0.69.0

tido64 commented 2 years ago

Does Hermes support all of these features?

retyui commented 2 years ago

I don't have any ideas what Hermes support (

tido64 commented 2 years ago

If I understand this setting correctly, I don't think we should recommend ES2019 when Hermes is our lowest common denominator. It doesn't mean that you can't have ES2019 in your own codebase though. You're free to bump it if you don't use Hermes or use your own polyfills.

retyui commented 2 years ago

Let's try look at it from developer perspective

He/She creates a new React Native project then add typescript support, and tried to use one of modern methods:

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.

And as result the Typescript thrown and error, with suggestion Try changing the 'lib' compiler option to 'es2019' or later

Developer is smart and decided to check it in runtime, run it on iOS everything OK, run it on Android everything OK. No runtime exceptions!!!


What conclusions can he/she draw?

Then make a release and started getting bad review that app is crashing (for iOS 11.0...12.3 users)


From my point of view this a big gab, why documentation doesn't explained why es2017 is default lib option

Agree, that's not required to update lib to 2019 but we definitely need to clarify it

tido64 commented 2 years ago

Yes, we should clarify this in the documentation.

retyui commented 2 years ago

Does Hermes support all of these features?

@tido64 Now I can answer this question, All es2019 lib features supported by the 3 latest Hermes versions

image

See more: https://retyui.github.io/react-native-compat-table/

tido64 commented 2 years ago

This is really awesome! How did you generate this table? I guess we should recommend 2019 then?

tido64 commented 2 years ago

Or maybe we should be more granular, e.g. ["ES2017.object", "ES2017.String", ...]. I know Intl support isn't complete, so the table is a bit misleading there.

retyui commented 2 years ago

In TypeScript 4.5, lib files can be overriden by npm modules, find out more in the blog.

also, we can define custom lib

{
 "dependencies": {
    "@typescript/lib-2017": "npm:@types/hermes-0-11-0"
  }
}

but it is required modern version of TS

github-actions[bot] commented 2 years ago

👋 Hey there, it looks like there has been no activity on this issue in the last 90 days. Has the issue been fixed, or does it still require the community attention? This issue will be closed in the next 7 days if no further activity occurs. Thank you for your contributions.

retyui commented 2 years ago