0

Functional component with render function:

render(createElement, { listeners } {
  return createElement('div', {
    on: {
      click: () => {
        // issue is on this line
        const onItemClick: any = listeners['item-click']
        onItemClick(1, 2, 3)
      }
    }
  })
}

How to correctly type onItemClick so i won't get an error:

const onItemClick: Function | Function[]
This expression is not callable.
  No constituent of type 'Function | Function[]' is callable.ts(2349)

Signature of listeners:

var listeners: {
    [key: string]: Function | Function[];
}
1
  • It says array is not callable, check if array -> call each else call value Commented Jul 9, 2020 at 7:10

2 Answers 2

1

Solved it using type assertion:

const onItemClick = listeners['item-click'] as (val1: string, val2: string) => void
onItemClick('123, '456')
Sign up to request clarification or add additional context in comments.

1 Comment

Type assertion is not a true solution and seems like a workaround. I wonder why the type is Function | Function[].
0

Try replacing the arrow function with the function() constructor.

on: { click: function() { // do the stuff }}

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.