1

I am creating an Application using react-redux. In that i am using typescript and immutable.js. When i use immutable methods like updateIn(), for a typed object, it is throwing error.

Following is the code which i tried:

interface aType{
  id: number
}

function randFun(a:aType){
  a = a.updateIn([....]); //It is throwing error in this line of code.
}
randFun({id:2});

Property 'updateIn' doesn't exist in on type {...}

How can i get rid of this error???

2
  • If you are going to use immutable js you have to give up using interfaces for your immutable objects so you would have to replace aType interface with Map interface in the immutable definition file Commented Jan 2, 2016 at 9:48
  • You may also check out github.com/engineforce/ImmutableAssign, which is a lightweight immutable helper that supports TypeScript type checking, and allows you to continue working with POJO (Plain Old JavaScript Object). Commented Jun 22, 2016 at 13:36

1 Answer 1

1

As for TypeScript, it's because updateIn is not defined in aType interface. To fix it, you can write:

interface aType{
  id: number,
  updateIn(n: number): aType
}

function randFun(a:aType){
  let n = 5;    
  a = a.updateIn(n); // No error here
}
randFun({id:2}); // This still need to be fixed!

However, it can't work in JavaScript too because you can't call updateIn on {id:2} object.

Sign up to request clarification or add additional context in comments.

3 Comments

updateIn() is an immutable.js method as i mention in the question.
Do you use definition file github.com/facebook/immutable-js/blob/master/type-definitions/… for immutable.js?
Yeah i used definition file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.