@@ -69,6 +69,30 @@ function checkValidInput(usedKey: string, value: any) {
69
69
}
70
70
}
71
71
72
+ function checkValidArgs ( keyValuePairs , callback ) {
73
+ if (
74
+ ! Array . isArray ( keyValuePairs ) ||
75
+ keyValuePairs . length === 0 ||
76
+ ! Array . isArray ( keyValuePairs [ 0 ] )
77
+ ) {
78
+ throw new Error (
79
+ '[AsyncStorage] Expected array of key-value pairs as first argument to multiSet' ,
80
+ ) ;
81
+ }
82
+
83
+ if ( callback && typeof callback !== 'function' ) {
84
+ if ( Array . isArray ( callback ) ) {
85
+ throw new Error (
86
+ '[AsyncStorage] Expected function as second argument to multiSet. Did you forget to wrap key-value pairs in an array for the first argument?' ,
87
+ ) ;
88
+ }
89
+
90
+ throw new Error (
91
+ '[AsyncStorage] Expected function as second argument to multiSet' ,
92
+ ) ;
93
+ }
94
+ }
95
+
72
96
/**
73
97
* `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value
74
98
* storage system that is global to the app. It should be used instead of
@@ -321,6 +345,7 @@ const AsyncStorage = {
321
345
keyValuePairs : Array < Array < string >> ,
322
346
callback ?: ?( errors : ?$ReadOnlyArray < ?Error > ) => void ,
323
347
) : Promise < null > {
348
+ checkValidArgs ( keyValuePairs , callback ) ;
324
349
return new Promise ( ( resolve , reject ) => {
325
350
keyValuePairs . forEach ( ( [ key , value ] ) => {
326
351
checkValidInput ( key , value ) ;
0 commit comments