Currently,
echarts/types/dist/echarts.d.ts and echarts/types/dist/core.d.ts(import echarts/types/dist/shared.d.ts internally)
use duplicated type declarations.
import {xxx} from 'echarts'; // use `echarts/types/dist/echarts.d.ts`
import {xxx} from 'echarts/core'; // use `echarts/types/dist/core.d.ts`
But there is an issue:
import {use as use1} from 'echarts';
import {use as use2} from 'echarts/core';
let someInstaller1 = {} as Parameters<typeof use1>[0]
use2(someInstaller1);
// TS error: "Types have separate declarations of a private property",
// because the parameters of `use` reference to some classes (such as, GlobalModel) that have private members,
// and TS handles classes with private or protected members break structural compatibility unless they come
// from the exact same declaration.
In most cases, it not a concern, as from 'echarts' and from 'echarts/core' is not used together.
But if some upper-level lib intents to import echarts types, it creates a problem of whether to use from 'echarts' or from 'echarts/core'.
Note:
class Some1 {
private theme: string = '';
}
type Some1Type = Some1;
class Some2 {
private theme: string = '';
}
type Some2Type = Some2;
let some1: Some1Type = new Some1();
let some2: Some2Type = new Some2();
some2 = some1; // TS error: "Types have separate declarations of a private property"
At present, echarts/types/dist/echats.js serves as a standalone file for echarts examples website running in the browser. (https://echarts.apache.org/en/js/vendors/echarts/types/dist/echarts.d.ts)
Therefore, to satisfy both of the issues above, a fix can be:
echarts/types/dist/echarts.d.ts is changed to import echarts/types/dist/shared.d.ts to avoid type confliction.
- Rename the current
echarts/types/dist/echarts.d.ts to echarts/types/dist/echarts.bundle.d.ts, and echarts website imports this file.
Currently,
echarts/types/dist/echarts.d.tsandecharts/types/dist/core.d.ts(importecharts/types/dist/shared.d.tsinternally)use duplicated type declarations.
But there is an issue:
In most cases, it not a concern, as
from 'echarts'andfrom 'echarts/core'is not used together.But if some upper-level lib intents to import echarts types, it creates a problem of whether to use
from 'echarts'orfrom 'echarts/core'.At present,
echarts/types/dist/echats.jsserves as a standalone file for echarts examples website running in the browser. (https://echarts.apache.org/en/js/vendors/echarts/types/dist/echarts.d.ts)Therefore, to satisfy both of the issues above, a fix can be:
echarts/types/dist/echarts.d.tsis changed to importecharts/types/dist/shared.d.tsto avoid type confliction.echarts/types/dist/echarts.d.tstoecharts/types/dist/echarts.bundle.d.ts, and echarts website imports this file.