apache / apache/echarts

[Bug] TS type confliction

Open
#21,198 0 comments 1 reaction 0 assignees View on GitHub
bug en typescript
Dominant language
TypeScript
Stars
67.3k
Forks
19.8k
Avg merge
11d 14h
Merged PRs (30d)
8

Description

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.
```ts
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:
```ts
import {use as use1} from 'echarts';
import {use as use2} from 'echarts/core';
let someInstaller1 = {} as Parameters[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:
> ```ts
> 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:
1. `echarts/types/dist/echarts.d.ts` is changed to import `echarts/types/dist/shared.d.ts` to avoid type confliction.
2. Rename the current `echarts/types/dist/echarts.d.ts` to `echarts/types/dist/echarts.bundle.d.ts`, and echarts website imports this file.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.