Skip to content

Export CallbackDataParams and TopLevelFormatterParams for formatter callbacks#21690

Open
kirthi-b wants to merge 1 commit into
apache:masterfrom
kirthi-b:feat/export-formatter-param-types
Open

Export CallbackDataParams and TopLevelFormatterParams for formatter callbacks#21690
kirthi-b wants to merge 1 commit into
apache:masterfrom
kirthi-b:feat/export-formatter-param-types

Conversation

@kirthi-b

Copy link
Copy Markdown

What does this PR do?

This exports the types of the params argument that ECharts passes to formatter callbacks, so TypeScript users can type those callbacks without reaching into internal paths.

Two types are now importable from the package entry:

  • CallbackDataParams - the per-item params object passed to label.formatter, and to each element of the array a series-grouped tooltip.formatter receives.
  • TopLevelFormatterParams - the exact type of the params argument of tooltip.formatter (CallbackDataParams | CallbackDataParams[]).

Why?

Today people either type params as any and lose all checking, copy the interface by hand, or import from an internal path such as echarts/types/dist/shared.js. All of those break as soon as the internals move. With this change the supported usage is:

import type { CallbackDataParams, TopLevelFormatterParams } from 'echarts';

const formatter = (params: TopLevelFormatterParams) => {
  const list = Array.isArray(params) ? params : [params];
  return list.map(p => p.seriesName).join(', ');
};

The aliases DefaultLabelFormatterCallbackParams and TooltipComponentFormatterCallbackParams already existed on the ESM types entry, but the base names were not exported and neither name reached the CJS types entry. This re-exports the base names from the core export, which feeds both entries, so the types resolve regardless of module resolution mode. The change is type-only, with no runtime output.

Closes #14277

Re-export CallbackDataParams and TopLevelFormatterParams from the core
export so tooltip.formatter and label.formatter callbacks can be typed
with `import type { ... } from 'echarts'` instead of reaching into
internal paths like 'echarts/types/dist/shared'.

Closes apache#14277
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export types for formatter callback params

1 participant