You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the updateIn, if the keyPath does not match the object, then we call this line, that does construct its error message with keyPath.slice(0, i), but .slice might not exist on a custom ArrayLike method.
classCustomArrayLike<T>implementsArrayLike<T>{readonlylength: number;readonly[n: number]: T;constructor(length: number){this.length=length;for(leti=0;i<length;i++){this[i]=undefinedasany;}}// Define other methods if needed, but do not include the `slice` method// For example, you can define a method to set valuesset(index: number,value: T): void{if(index>=0&&index<this.length){this[index]=value;}else{thrownewRangeError('Index out of bounds');}}// Define a method to get valuesget(index: number): T{if(index>=0&&index<this.length){returnthis[index];}else{thrownewRangeError('Index out of bounds');}}}
Code that throws
// create an ArrayLikeconstcustomArray=newCustomArrayLike<number>(2);customArray.set(0,10);customArray.set(1,20);// code that works perfectlyImmutable.updateIn({10 :{20 : 'a'}},customArray2,(v)=>`${v.toUpperCase()}`)// does output { 10 :{ 20 : 'A' }}Immutable.updateIn({10 : 'a'},customArray2,(v)=>`${v.toUpperCase()}`)// does throw Uncaught TypeError: keyPath.slice is not a function
The text was updated successfully, but these errors were encountered:
Description
The
updateIn
function does callcoerceKeyPath
on the keyPath.The coerceKeyPath does check if the keyPath is an "ArrayLike". If true, the value is kept.
In the updateIn, if the keyPath does not match the object, then we call this line, that does construct its error message with
keyPath.slice(0, i)
, but.slice
might not exist on a custom ArrayLike method.Here is the implementation of
isArrayLike
: https://github.com/immutable-js/immutable-js/blob/main/src/utils/isArrayLike.tsReproductible example
Define the custom array
Code that throws
The text was updated successfully, but these errors were encountered: