1

I have the following code:

  function parseValueFromComplexType(complexType, item) {
                return item[complexType];
            }

In order to bind the value complextype, i use angular.bind

let parseValueFromComplexTypeWithValue = angular.bind('', parseValueFromComplexType , config.complexType);
val.values = val.values.map(parseValueFromComplexTypeWithValue);

Now typescript complains:

error TS2345: Argument of type 'Function' is not assignable to parameter of type '(value: any, index: number, array: any[]) => {}'.

What does the error mean and how can i get rid of it?

1 Answer 1

2

The map function accepts a function with three parameters, in this structure:

callbackfn: (value: T, index: number, array: T[]) => U

The bind function of angular returns a simple Function type:

bind(context: any, fn: Function, ...args: any[]): Function;

The error say: You can't put just a Function where a callbackfn: (value: T, index: number, array: T[]) => U is expected.

Another issue here is that you are trying to use angular bind in a very weird way... If you want to preserve the this just use an arrow function.

Maybe something (Much simpler) like this:

var complexType = 'str';
val.values = val.values.map((item, index, array) => item[complexType]);
Sign up to request clarification or add additional context in comments.

Comments

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.