@@ -69,6 +69,30 @@ function checkValidInput(usedKey: string, value: any) {
6969 }
7070}
7171
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+
7296/**
7397 * `AsyncStorage` is a simple, unencrypted, asynchronous, persistent, key-value
7498 * storage system that is global to the app. It should be used instead of
@@ -321,6 +345,7 @@ const AsyncStorage = {
321345 keyValuePairs : Array < Array < string >> ,
322346 callback ?: ?( errors : ?$ReadOnlyArray < ?Error > ) => void ,
323347 ) : Promise < null > {
348+ checkValidArgs ( keyValuePairs , callback ) ;
324349 return new Promise ( ( resolve , reject ) => {
325350 keyValuePairs . forEach ( ( [ key , value ] ) => {
326351 checkValidInput ( key , value ) ;
0 commit comments