fix(types): remove export assignment to support typescript esm compatibility
See https://github.com/apache/echarts/issues/21250
Brief Information
This pull request is in the type of:
- [x] 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.
- [x] 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
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.
@Ovilia Can you take a look at the PR 🙇
@100pah @Ovilia any update on this PR
@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, andindex.d.tshas been corresponding to it, where statementsexport = echartsandexport as namespace echartsprovide types for the UMD bundle. However, they effectively mismatches the ESM entry.tscno longer tolerates this mismatch since TSv5.6and reports errorTS1203. Therefore, ESM entries and UMD entries are separately provided.
- echarts has been providing a UMD bundle (
-
Explicit file extensions:
- Previously echarts used extensionless path in DTS, e.g.,
"from "echarts/types/dist/core". However, explicit file extensions are required whenpackage.jsonuses"type": "module"andtsconfig.jsonuses"moduleResolution": "NodeNext"; otherwise TS errorTS2834occurs. - This new modification uses pseudo
.jsto redirect to.d.ts, e.g.,export {some} from "echarts/types/dist/core.js". If using"from "echarts/types/dist/core.d.ts", TS errorTS2846occurs.
- Previously echarts used extensionless path in DTS, e.g.,
-
Avoid duplicated type declarations:
- Previously in
echarts/type/echarts.d.tsandecharts/type/dist/shared.d.tstypes 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);
- issue1:
- In this new modification,
echarts/type/dist/all.d.tsecharts/type/dist/core.d.tsecharts/type/dist/option.d.tsecharts/type/dist/features.d.tsecharts/type/dist/components.d.tsecharts/type/dist/charts.d.tsecharts/type/dist/renderers.d.tsimport type declarations from a single sourceecharts/types/dist/shared.d.ts.
- Previously in
-
CJS and ESM interop under
"NodeNext":- TSv4.7~TSv5.7 disallows
requirea ESM file from a CJS file whenmoduleResolution: "NodeNext"(introduced in TSv4.7); otherwise TS errorTS1471may arise. Therefore, the new modification useecharts.d.ctsinstead ofd.tsfor CJS case, and make it self-contained to avoid importing ESM from CJS DTS.
- TSv4.7~TSv5.7 disallows
Close #21250 , Close #20554
Congratulations! Your PR has been merged. Thanks for your contribution! 👍