What problem does this feature solve?
would allow to define callback formatter with properly typed arguments: for now I have to type params
to any
, loosing typing within the formatter function. For instance:
tooltip.formatter = (params: any) => {
// access to whatever in params is allowed
...
return content;
};
What does the proposed API look like?
As I get it, params
is expected to be of FormatterParams
type, so exporting in within echarts.d.ts would allow something along the line of :
import {FormatterParams} from "echarts";
...
tooltip.formatter = (params: FormatterParams) => {
// compilation error on access to something to defined in FormatterParams
return content;
};
5条答案
按热度按时间polkgigr1#
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 dev@echarts.apache.org . 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! 🍵
7fyelxc52#
模块“"echarts"”没有导出的成员“FormatterParams”。
mpgws1up3#
Hello, 👋
Any news regarding this point please ?
z6psavjg4#
echarts/src/component/tooltip/TooltipView.ts
Line 127 in 75dd430
| | typeTooltipCallbackDataParams=CallbackDataParams&{ |
uubf1zoe5#
I'm also stuck on this.
Typescript squiggly lines
.value
and reports:Well,
TopLevelFormatterParams
looks like this:Since properties like
value
ordimensionNames
etc live onCallbackDataParams
type (not an array), you can't guarantee you can access it via theTopLevelFormatterParams
type which is why Typescript is throwing an error. It's also why you can't doparams[0].value
because, again, using the typeTopLevelFormatterParams
does not guarantee the typeCallbackDataParams[]
.You can't really do anything other than
(params: any)
since the union of types byTopLevelFormatterParams
conflict with each other.I am new to TypeScript so if there's a solution here that I'm not seeing please let me know...
Edit: I guess instead of
any
you could assert the type if you know for sure it will be one or the other, then you at least get intellisense (VS Code) working with the various properties available:You could also write a type guard, but you still have to use
// @ts-ignore
to suppress errors for a few properties due to other typing problems. The code will run fine despite typescript complaining.