Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type export missing for tooltip formatter callback #14723

Closed
Bilge opened this issue Apr 20, 2021 · 3 comments
Closed

Type export missing for tooltip formatter callback #14723

Bilge opened this issue Apr 20, 2021 · 3 comments
Labels
duplicate en This issue is in English new-feature pending We are not sure about whether this is a bug/new feature. typescript

Comments

@Bilge
Copy link
Contributor

Bilge commented Apr 20, 2021

What problem does this feature solve?

It is difficult to write a tooltip formatter in a typed application because it seems the necessary type is not exported. As far as I can tell, the type is declared as TooltipFormatterCallback<TopLevelFormatterParams>, but since the type is not exported in 5.0.2, it cannot be consumed in the user's application.

@echarts-bot
Copy link

echarts-bot bot commented Apr 20, 2021

Hi! We've received your issue and please be patient to get responded. 🎉
The average response time is expected to be within one day for weekdays.

In the meanwhile, please make sure that you have posted enough image to demo your request. You may also check out the API and chart option to get the answer.

If you don't get helped for a long time (over a week) or have an urgent question to ask, you may also send an email to [email protected]. Please attach the issue link if it's a technical question.

If you are interested in the project, you may also subscribe our mailing list.

Have a nice day! 🍵

@echarts-bot echarts-bot bot added en This issue is in English new-feature pending We are not sure about whether this is a bug/new feature. waiting-for: community labels Apr 20, 2021
@plainheart
Copy link
Member

plainheart commented Apr 20, 2021

Related to #14277. It seems this type should be exported indeed.

Currently, as a workaround, we can get it like this, (slightly complicated)

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 || ''
}

@Ovilia
Copy link
Contributor

Ovilia commented Apr 23, 2021

Please follow #14277 for future information.

@Ovilia Ovilia closed this as completed Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate en This issue is in English new-feature pending We are not sure about whether this is a bug/new feature. typescript
Projects
None yet
Development

No branches or pull requests

3 participants