1

I'm trying to pass a generic type to a callback lambda function

interface Interface { 
   onChange: <T = string>(val: T) => void 
}

const handleOnChange = (val: MY_ENUM) => {...}

const myConfig: Interface[] = [{
    onChange: <MY_ENUM>(val) => handleOnChange(val);
}]

the code above doesn't work.

CodeNewbie
  • 173
  • 1
  • 10

1 Answers1

0
interface Interface {
  onChange: <T = string>(val: T) => void
}

const handleOnChange = <T,>(val: T) => { }

const myConfig: Interface[] = [{
  onChange: handleOnChange
}]

You had to add a COMMA at the beginning of your config function when passing the generic
Thanks to, @captain-yossarian

CodeNewbie
  • 173
  • 1
  • 10