0

I define the following interface

interface Axis {
  renderTick?: <T>(data: T) => React.ReactNode
}

And now I want to make an object that uses that interface.

interface CustomData {
  name: string
} 

const renderTick: (data: CustomData) => ReactNode = ({name}: CustomData) => (<>{name}</>)
const axis: Axis = {
  renderTick: renderTick
}

I had "Type 'T' is not assignable to type 'CustomData'" error

Cragser
  • 166
  • 4

1 Answers1

0

You can use generic.

Try

interface Axis<T> {
  renderTick?: (data: T) => React.ReactNode
}

interface CustomData {
  name: string
} 

const renderTick = ({name}: CustomData) => (<>{name}</>)
const axis: Axis<CustomData> = {
  renderTick: renderTick
}

Use Axis generic T.

hyundeock
  • 445
  • 1
  • 6
  • 15