@@ -52,6 +52,14 @@ type MultiRequest = {|
52
52
reject : ?( error ? : any ) => void ,
53
53
| } ;
54
54
55
+ function checkValueTypeNotString ( value : any , usedKey : string ) {
56
+ if ( typeof value !== 'string' ) {
57
+ console . warn (
58
+ `[AsyncStorage] The value for key "${ usedKey } " is not a string. This can lead to unexpected behavior/errors. Consider stringifying it.` ,
59
+ ) ;
60
+ }
61
+ }
62
+
55
63
/**
56
64
* `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value
57
65
* storage system that is global to the app. It should be used instead of
@@ -100,6 +108,7 @@ const AsyncStorage = {
100
108
) : Promise < null > {
101
109
return new Promise ( ( resolve , reject ) => {
102
110
RCTAsyncStorage . multiSet ( [ [ key , value ] ] , function ( errors ) {
111
+ checkValueTypeNotString ( value , key ) ;
103
112
const errs = convertErrors ( errors ) ;
104
113
callback && callback ( errs && errs [ 0 ] ) ;
105
114
if ( errs ) {
@@ -301,6 +310,10 @@ const AsyncStorage = {
301
310
callback ?: ?( errors : ?$ReadOnlyArray < ?Error > ) => void ,
302
311
) : Promise < null > {
303
312
return new Promise ( ( resolve , reject ) => {
313
+ keyValuePairs . forEach ( ( [ key , value ] ) => {
314
+ checkValueTypeNotString ( value , key ) ;
315
+ } ) ;
316
+
304
317
RCTAsyncStorage . multiSet ( keyValuePairs , function ( errors ) {
305
318
const error = convertErrors ( errors ) ;
306
319
callback && callback ( error ) ;
0 commit comments