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

Type mismatch: inferred type is String? but String was expected #2871

Closed
nes123 opened this issue Oct 27, 2024 · 4 comments · Fixed by #2872 or 7xq/react-native-iap#1
Closed

Type mismatch: inferred type is String? but String was expected #2871

nes123 opened this issue Oct 27, 2024 · 4 comments · Fixed by #2872 or 7xq/react-native-iap#1

Comments

@nes123
Copy link

nes123 commented Oct 27, 2024

I get the following error:
java/com/dooboolab/RNIap/PromiseUtlis.kt:40:21 Type mismatch: inferred type is String? but String was expected

Environment:

  • react-native-iap: 12.15.6
  • react-native: 0.76
  • Platforms (iOS, Android, emulator, simulator, device): android
mlazari added a commit to mlazari/react-native-iap that referenced this issue Oct 27, 2024
When using React Native 0.76 the Android build fails with an error:
```
java/com/dooboolab/RNIap/PromiseUtlis.kt:40:21 Type mismatch: inferred type is String? but String was expected
```

The issue seems to be caused by the fact that in RN 0.76 the Promise class was rewritten from Java to Kotlin and the code parameter of the reject method is a non-nullable String now: facebook/react-native@de73e44#diff-74cbd5a9d82e4c21dbc37dd72a92e31542e574dc6425d2454c3ce53e71e08bbeR31 but in react-native-iap it is called with a nullable string.

This change updates that call to use an empty string "" for code if for some reason it's null.

Fixes hyochan#2871
mlazari added a commit to mlazari/react-native-iap that referenced this issue Oct 27, 2024
When using React Native 0.76 the Android build fails with an error:
```
java/com/dooboolab/RNIap/PromiseUtlis.kt:40:21 Type mismatch: inferred type is String? but String was expected
```

The issue seems to be caused by the fact that in RN 0.76 the Promise class was rewritten from Java to Kotlin and the code parameter of the reject method is a non-nullable String now: facebook/react-native@de73e44#diff-74cbd5a9d82e4c21dbc37dd72a92e31542e574dc6425d2454c3ce53e71e08bbeR31 but in react-native-iap it is called with a nullable string.

This change updates that call to use an empty string "" for code if for some reason it's null.

Fixes hyochan#2871
mlazari added a commit to mlazari/react-native-iap that referenced this issue Oct 27, 2024
When using React Native 0.76 the Android build fails with an error:
```
java/com/dooboolab/RNIap/PromiseUtlis.kt:40:21 Type mismatch: inferred type is String? but String was expected
```

The issue seems to be caused by the fact that in RN 0.76 the Promise class was rewritten from Java to Kotlin and the code parameter of the reject method is a non-nullable String now: facebook/react-native@de73e44#diff-74cbd5a9d82e4c21dbc37dd72a92e31542e574dc6425d2454c3ce53e71e08bbeR31 but in react-native-iap it is called with a nullable string: https://github.com/hyochan/react-native-iap/blob/12.15.6/android/src/main/java/com/dooboolab/rniap/PromiseUtlis.kt#L40.

This change updates that call to use an empty string "" for code if for some reason it's null.

Fixes hyochan#2871
@sontruongna
Copy link

Same here

@mlazari
Copy link
Contributor

mlazari commented Oct 28, 2024

Hi, I opened a PR here: #2872
In the meantime you can use this patch:
react-native-iap+12.15.6.patch

@dmk3141618
Copy link

Same error.

It seems critical error. When will it be updated in the official version?

@dmk3141618
Copy link

dmk3141618 commented Oct 29, 2024

It worked after applying the fix! Thank you for your great work.

     try {
-        this.reject(code, message, throwable)
+        this.reject(code ?: "", message, throwable)
     } catch (oce: ObjectAlreadyConsumedException) {
         Log.d(TAG, "Already consumed ${oce.message}")
     }
fun Promise.safeReject(
    code: String?,
    message: String?,
    throwable: Throwable?,
) {
    try {
        this.reject(code ?: "", message, throwable)
    } catch (oce: ObjectAlreadyConsumedException) {
        Log.d(TAG, "Already consumed ${oce.message}")
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants