score:5

Accepted answer

if you check thoroughly your statevariable<t> type you may notice that setvalue field of that type has signature:

setvalue: (value: t) => void

while you're trying to feed it instead of a value of type t the value (function) of type: (prevstate: t) => t.

to match your function implementation the type statevariable should be defined as:

interface statevariable<t> {
  value: t;
  setvalue: (cb: (value: t) => t) => void;
}

react exposes special helper types for typing usestate dispatch functions: dispatch<setstateaction<t>> so you may write it also as:

import { dispatch, setstateaction } from 'react'

interface statevariable<t> {
  value: t
  setvalue: dispatch<setstateaction<t>>
}

Related Query

More Query from same tag