You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/04/20 17:24:54 UTC

[GitHub] [echarts] plainheart edited a comment on issue #14723: Type export missing for tooltip formatter callback

plainheart edited a comment on issue #14723:
URL: https://github.com/apache/echarts/issues/14723#issuecomment-823460802


   Related to #14277. It seems this type should be exported indeed.
   
   Currently, as a workaround, we can get it like this, (slightly complicated)
   
   ```ts
   import { TooltipComponentOption } from 'echarts/components'
   
   type Unified<T> = Exclude<T, T[]>
   type TooltipFormatterCallback = Exclude<NonNullable<TooltipComponentOption['formatter']>, string>
   // single and multiple params
   type TooltipFormatterParams = Parameters<TooltipFormatterCallback>[0]
   // single params
   type SingleTooltipFormatterParams = Unified<TooltipFormatterParams>
   // multiple params
   type MultipleTooltipFormatterParams = SingleTooltipFormatterParams[]
   
   const formatter0: TooltipFormatterCallback = (params: TooltipFormatterParams) => {
     if (Array.isArray(params)) {
       return params[0].seriesName || ''
     }
     return params.seriesName || ''
   }
   
   const formatter1: TooltipFormatterCallback = (params: SingleTooltipFormatterParams) => {
     return params.seriesName || ''
   }
   
   const formatter2: TooltipFormatterCallback = (params: MultipleTooltipFormatterParams) => {
     return params[0].seriesName || ''
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org