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

[Feature] filtering an array of series by type should return the right TypeScript Type #16630

Closed
Joaveinz opened this issue Mar 4, 2022 · 1 comment
Labels
en This issue is in English not-related This is not related directly to ECharts.

Comments

@Joaveinz
Copy link

Joaveinz commented Mar 4, 2022

Version

5.2.2

Link to Minimal Reproduction

No response

Steps to Reproduce

  1. Have an option with multiple series
  2. filter the option series by type

Current Behavior

I want to toggle the "smooth" property of my chart series.

Currently, I have to use this if statement:

inside the foreach statement, set is of type SeriesOption$1
Inside the if statement, set is of type LineSeriesOption$1

option.value.series.forEach((set) => {
    if (set.type === "line") {
        set.smooth = !set.smooth;
    }
});

Expected Behavior

I would like the filter to return LineSeriesOption$1, so I can use the following code:

option.value.series.filter((set) => set.type === "line").forEach((set) => {
    set.smooth = !set.smooth;
});

Environment

- OS: macOS Monterey M1 2020
- Browser: Chrome
- Framework: Vue 3 + vue-echarts library

Any additional comments?

Just a note, not high priority for me.

@Joaveinz Joaveinz added the bug label Mar 4, 2022
@echarts-bot echarts-bot bot added en This issue is in English pending We are not sure about whether this is a bug/new feature. waiting-for: community labels Mar 4, 2022
@pissang
Copy link
Contributor

pissang commented Mar 7, 2022

Seems it's the limitation of TypeScript. There is no type narrowing for the filter method. See microsoft/TypeScript#20812 (comment)

@pissang pissang added not-related This is not related directly to ECharts. and removed bug pending We are not sure about whether this is a bug/new feature. labels Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
en This issue is in English not-related This is not related directly to ECharts.
Projects
None yet
Development

No branches or pull requests

3 participants