akashsonune commented on PR #21411:
URL: https://github.com/apache/echarts/pull/21411#issuecomment-3682297047

   > @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:
   >       ```ts
   >       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:
   >       ```ts
   >       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 👍 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to