Skip to content

Conversation

@akashsonune
Copy link
Contributor

@akashsonune akashsonune commented Dec 5, 2025

See #21250

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Fixed issues

Details

Before: What was the problem?

After: How does it behave after the fixing?

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

Security Checking

  • This PR uses security-sensitive Web APIs.

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

N.A.

Merging options

  • Please squash the commits into a single one when merging.

Other information

@echarts-bot
Copy link

echarts-bot bot commented Dec 5, 2025

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only.

⚠️ MISSING DOCUMENT INFO: Please make sure one of the document options are checked in this PR's description. Search "Document Info" in the description of this PR. This should be done either by the author or the reviewers of the PR.

@akashsonune akashsonune changed the title fix(types): remove export assignment to support typescript esm compat… fix(types): remove export assignment to support typescript esm compatibility Dec 5, 2025
@akashsonune
Copy link
Contributor Author

@Ovilia Can you take a look at the PR 🙇

This comment was marked as off-topic.

@Ovilia Ovilia requested a review from 100pah December 10, 2025 06:44
@akashsonune
Copy link
Contributor Author

@100pah @Ovilia any update on this PR

@100pah
Copy link
Member

100pah commented Dec 18, 2025

@akashsonune Thank you for this contribution. I made some modification based on your code, including:

  • Separated ESM and CJS(UMD) TS entries:

    • echarts has been providing a UMD bundle (echarts/dist/echarts.js) as one of the default entries, and index.d.ts has been corresponding to it, where statements export = echarts and export as namespace echarts provide types for the UMD bundle. However, they effectively mismatches the ESM entry. tsc no longer tolerates this mismatch since TS v5.6 and reports error TS1203. Therefore, ESM entries and UMD entries are separately provided.
  • Explicit file extensions:

    • Previously echarts used extensionless path in DTS, e.g., "from "echarts/types/dist/core". However, explicit file extensions are required when package.json uses "type": "module" and tsconfig.json uses "moduleResolution": "NodeNext"; otherwise TS error TS2834 occurs.
    • This new modification uses pseudo .js to redirect to .d.ts, e.g., export {some} from "echarts/types/dist/core.js". If using "from "echarts/types/dist/core.d.ts", TS error TS2846 occurs.
  • Avoid duplicated type declarations:

    • Previously in echarts/type/echarts.d.ts and echarts/type/dist/shared.d.ts types are defined in duplicate. It causes issues:
      • issue1:
        import {use} from 'echarts';
        import {BarChart} from 'echarts/charts';
        use([BarChart]);
        // TS error TS2442 may throws.
        // Although this usage is not recommended officially, misuse may occur.
      • issue2:
        import {use as use1} from 'echarts';
        import {use as use2} from 'echarts/core';
        import {violinCustomSeriesInstaller} from '@echarts-x/custom-violin';
        // Now how to make type for `violinCustomSeriesInstaller` to support
        // both and TS2442 does not occur?
        use1(violinCustomSeriesInstaller);
        use2(violinCustomSeriesInstaller);
    • In this new modification, echarts/type/dist/all.d.ts echarts/type/dist/core.d.ts echarts/type/dist/option.d.ts echarts/type/dist/features.d.ts echarts/type/dist/components.d.ts echarts/type/dist/charts.d.ts echarts/type/dist/renderers.d.ts import type declarations from a single source echarts/types/dist/shared.d.ts.
  • CJS and ESM interop under "NodeNext":

    • TSv4.7~TSv5.7 disallows require a ESM file from a CJS file when moduleResolution: "NodeNext" (introduced in TSv4.7); otherwise TS error TS1471 may arise. Therefore, the new modification use echarts.d.cts instead of d.ts for CJS case, and make it self-contained to avoid importing ESM from CJS DTS.

Close #21250 , Close #20554

@100pah 100pah merged commit 83ee45c into apache:master Dec 18, 2025
@echarts-bot
Copy link

echarts-bot bot commented Dec 18, 2025

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

@akashsonune
Copy link
Contributor Author

@akashsonune Thank you for this contribution. I made some modification based on your code, including:

  • Separated ESM and CJS(UMD) TS entries:

    • echarts has been providing a UMD bundle (echarts/dist/echarts.js) as one of the default entries, and index.d.ts has been corresponding to it, where statements export = echarts and export as namespace echarts provide types for the UMD bundle. However, they effectively mismatches the ESM entry. tsc no longer tolerates this mismatch since TS v5.6 and reports error TS1203. Therefore, ESM entries and UMD entries are separately provided.
  • Explicit file extensions:

    • Previously echarts used extensionless path in DTS, e.g., "from "echarts/types/dist/core". However, explicit file extensions are required when package.json uses "type": "module" and tsconfig.json uses "moduleResolution": "NodeNext"; otherwise TS error TS2834 occurs.
    • This new modification uses pseudo .js to redirect to .d.ts, e.g., export {some} from "echarts/types/dist/core.js". If using "from "echarts/types/dist/core.d.ts", TS error TS2846 occurs.
  • Avoid duplicated type declarations:

    • Previously in echarts/type/echarts.d.ts and echarts/type/dist/shared.d.ts types are defined in duplicate. It causes issues:

      • issue1:
        import {use} from 'echarts';
        import {BarChart} from 'echarts/charts';
        use([BarChart]);
        // TS error TS2442 may throws.
        // Although this usage is not recommended officially, misuse may occur.
      • issue2:
        import {use as use1} from 'echarts';
        import {use as use2} from 'echarts/core';
        import {violinCustomSeriesInstaller} from '@echarts-x/custom-violin';
        // Now how to make type for `violinCustomSeriesInstaller` to support
        // both and TS2442 does not occur?
        use1(violinCustomSeriesInstaller);
        use2(violinCustomSeriesInstaller);
    • In this new modification, echarts/type/dist/all.d.ts echarts/type/dist/core.d.ts echarts/type/dist/option.d.ts echarts/type/dist/features.d.ts echarts/type/dist/components.d.ts echarts/type/dist/charts.d.ts echarts/type/dist/renderers.d.ts import type declarations from a single source echarts/types/dist/shared.d.ts.

  • CJS and ESM interop under "NodeNext":

    • TSv4.7~TSv5.7 disallows require a ESM file from a CJS file when moduleResolution: "NodeNext" (introduced in TSv4.7); otherwise TS error TS1471 may arise. Therefore, the new modification use echarts.d.cts instead of d.ts for CJS case, and make it self-contained to avoid importing ESM from CJS DTS.

Close #21250 , Close #20554

@100pah Thank you, this looks great 👍

@akashsonune
Copy link
Contributor Author

@100pah When is this planned for a release

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants