You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by "ChepteaCatalin (via GitHub)" <gi...@apache.org> on 2023/09/13 17:05:50 UTC

[GitHub] [echarts] ChepteaCatalin commented on issue #19064: [Bug] tooltip.formatter option is not typed correctly

ChepteaCatalin commented on issue #19064:
URL: https://github.com/apache/echarts/issues/19064#issuecomment-1718004681

   @yay I suggest you use the following workaround, which appears less awkward:
   
   ```typescript
           tooltip: {
               formatter: (params: echarts.DefaultLabelFormatterCallbackParams) => {
                   return `${params.name}, ${params.seriesName}`;
               }
           } as echarts.TooltipComponentOption
   ```
   
   `params` is expected to be of type `TooltipComponentFormatterCallbackParams` which is an alias for 
   
   ```typescript
   type TopLevelFormatterParams = CallbackDataParams | CallbackDataParams[];
   ```
   
   TypeScript will try to infer the most general type from the union that encompasses both possibilities even if you want to infer only `CallbackDataParams` type. In your case, `CallbackDataParams[]` is inferred because it's more general than just `CallbackDataParams`. So, you have to set explicitly that you want `CallbackDataParams`, which is exported as `DefaultLabelFormatterCallbackParams`.
   
   As mentioned in the [documentation](https://echarts.apache.org/en/option.html#tooltip.formatter), `params` can take the form of either an object or an array so I don't think that we should change anything in the library. @plainheart, what are your thoughts on this?
   
   
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org

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