Check input data type when targeting JavaScript
Kotlin is a statically typed language while JavaScript is a dynamically typed language. See Kotlin.
When using the CRDTlib with JavaScript, it didn't check the type of functions arguments. Therefore, we can get unexpected behaviors/errors.
For example: In JavaScript with the LWWMap, we can call setInt with a String without error. The map of Integer will contain a String whereas it is supposed to only contain integer values. When calling getInt, it will return null but when calling iteratorInt, it will throw an exception because we used toInt. There are many other similar situations.
Possible solutions for the LWWMap:
- Change to[Int/Double] to to[Int/Double]OrNull to return a null value instead of an exception,
- When targeting Javascript, add a type checking of the inserted value before the insertion. (preferred)
Should check it out if there are other similar problems.