Help with TypeScript Inference Issue in Callback Helper Function

chasing a typescript aficionado to help me nail down some typescript inference on a callback helper ive been wracking my brain over. got an effect playground ready to go. Essentially, i cannot get the map to infer type T, it keeps coming back as unknown....

function withCallback<T, U>(cb?: (...args: any) => void, map?: (t: T) => U) {
  return (value: T) => (cb ? cb(map ? map(value) : value) : constVoid());
}

// use case
Match.valueTags({
  HttpUnexpected: (err) => (opts?.onError ? opts.onError(err) : constVoid()),
  HttpBadRequest: (err) => (opts?.onError ? opts.onError(err) : constVoid()),
  HttpFormValidation: withCallback(opts?.onValidationError, (err) => ???), // err is unknown
  HttpUnauthorized: (err) => (opts?.onError ? opts.onError(err) : constVoid()),
}),


https://effect.website/play/#ec52d0bbd8cd
Was this page helpful?