Skip to content

Commit

Permalink
fix(type): support ts 3.4 in dts
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Nov 8, 2020
1 parent b46dc3d commit 2086398
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 45 deletions.
9 changes: 8 additions & 1 deletion build/pre-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,16 @@ async function bundleDTS() {
})
]
});
const bundleFile = nodePath.resolve(__dirname, '../types/dist/echarts.d.ts');
await bundle.write({
file: nodePath.resolve(__dirname, '../types/dist/echarts.d.ts')
file: bundleFile
});
// To support ts 3.4
const extra = `
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
`
const code = extra + fs.readFileSync(bundleFile, 'utf-8');
fs.writeFileSync(bundleFile, code, 'utf-8');
}

function readTSConfig() {
Expand Down
2 changes: 1 addition & 1 deletion build/testDts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { runTsCompile, readTSConfig } = require('./pre-publish');
const globby = require('globby');
const semver = require('semver');

const MIN_VERSION = '3.5.0';
const MIN_VERSION = '3.4.0';

async function installTs() {
// await cleanTypeScriptInstalls();
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/// Make sure run it before edit this file. ///
///////////////////////////////////////////////////////////////////////


// Restrict exports
export {
init, connect, disConnect, dispose, getInstanceByDom, getInstanceById,
Expand Down
4 changes: 3 additions & 1 deletion src/chart/bar/PictorialBarSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {
AnimationOptionMixin,
SeriesStackOptionMixin,
StatesOptionMixin,
OptionDataItemObject
OptionDataItemObject,
DefaultExtraEmpasisState
} from '../../util/types';
import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
import { inheritDefaultOption } from '../../util/component';
Expand Down Expand Up @@ -92,6 +93,7 @@ interface PictorialBarSeriesSymbolOption {

interface ExtraStateOption {
emphasis?: {
focus?: DefaultExtraEmpasisState['focus']
scale?: boolean
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/chart/boxplot/BoxplotSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
ItemStyleOption,
LabelOption,
OptionDataValueNumeric,
StatesOptionMixin
StatesOptionMixin,
DefaultExtraEmpasisState
} from '../../util/types';
import type Axis2D from '../../coord/cartesian/Axis2D';
import Cartesian2D from '../../coord/cartesian/Cartesian2D';
Expand All @@ -48,6 +49,7 @@ export interface BoxplotDataItemOption

interface ExtraStateOption {
emphasis?: {
focus?: DefaultExtraEmpasisState['focus']
scale?: boolean
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/chart/candlestick/CandlestickSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
LabelOption,
SeriesLargeOptionMixin,
OptionDataValueNumeric,
StatesOptionMixin
StatesOptionMixin,
DefaultExtraEmpasisState
} from '../../util/types';
import List from '../../data/List';
import Cartesian2D from '../../coord/cartesian/Cartesian2D';
Expand All @@ -53,6 +54,7 @@ export interface CandlestickDataItemOption

interface ExtraStateOption {
emphasis?: {
focus?: DefaultExtraEmpasisState['focus']
scale?: boolean
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/chart/graph/GraphSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import {
LineLabelOption,
StatesOptionMixin,
GraphEdgeItemObject,
OptionDataValueNumeric
OptionDataValueNumeric,
DefaultExtraEmpasisState
} from '../../util/types';
import SeriesModel from '../../model/Series';
import Graph from '../../data/Graph';
Expand All @@ -66,17 +67,16 @@ export interface GraphNodeStateOption {
label?: LabelOption
}


interface ExtraEmphasisState {
focus?: DefaultExtraEmpasisState['focus'] | 'adjacency'
}
interface ExtraNodeStateOption {
emphasis?: {
focus?: 'adjacency'
scale?: boolean
}
emphasis?: ExtraEmphasisState
}

interface ExtraEdgeStateOption {
emphasis?: {
focus?: 'adjacency'
}
emphasis?: ExtraEmphasisState
}

export interface GraphNodeItemOption extends SymbolOptionMixin, GraphNodeStateOption,
Expand Down
4 changes: 3 additions & 1 deletion src/chart/line/LineSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
OptionDataValue,
SymbolOptionMixin,
SeriesSamplingOptionMixin,
StatesOptionMixin
StatesOptionMixin,
DefaultExtraEmpasisState
} from '../../util/types';
import List from '../../data/List';
import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
Expand All @@ -41,6 +42,7 @@ type LineDataValue = OptionDataValue | OptionDataValue[];

interface ExtraStateOption {
emphasis?: {
focus?: DefaultExtraEmpasisState['focus']
scale?: boolean
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/chart/pie/PieSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
OptionDataValueNumeric,
SeriesEncodeOptionMixin,
OptionDataItemObject,
StatesOptionMixin
StatesOptionMixin,
DefaultExtraEmpasisState
} from '../../util/types';
import List from '../../data/List';

Expand Down Expand Up @@ -77,6 +78,7 @@ interface PieLabelLineOption extends LabelLineOption {

interface ExtraStateOption {
emphasis?: {
focus?: DefaultExtraEmpasisState['focus']
scale?: boolean
scaleSize?: number
}
Expand Down
5 changes: 3 additions & 2 deletions src/chart/sankey/SankeySeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
StatesOptionMixin,
OptionDataItemObject,
GraphEdgeItemObject,
OptionDataValueNumeric
OptionDataValueNumeric,
DefaultExtraEmpasisState
} from '../../util/types';
import GlobalModel from '../../model/Global';
import List from '../../data/List';
Expand Down Expand Up @@ -60,7 +61,7 @@ interface SankeyEdgeStyleOption extends LineStyleOption {

interface ExtraStateOption {
emphasis?: {
focus?: 'adjacency'
focus?: DefaultExtraEmpasisState['focus'] | 'adjacency'
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/chart/scatter/ScatterSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
SeriesStackOptionMixin,
SymbolOptionMixin,
StatesOptionMixin,
OptionDataItemObject
OptionDataItemObject,
DefaultExtraEmpasisState
} from '../../util/types';
import GlobalModel from '../../model/Global';
import List from '../../data/List';
Expand All @@ -46,6 +47,7 @@ interface ScatterStateOption {

interface ExtraStateOption {
emphasis?: {
focus?: DefaultExtraEmpasisState['focus']
scale?: boolean
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/chart/sunburst/SunburstSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
OptionDataValue,
CallbackDataParams,
StatesOptionMixin,
OptionDataItemObject
OptionDataItemObject,
DefaultExtraEmpasisState
} from '../../util/types';
import GlobalModel from '../../model/Global';
import List from '../../data/List';
Expand Down Expand Up @@ -65,7 +66,7 @@ interface SunburstDataParams extends CallbackDataParams {

interface ExtraStateOption {
emphasis?: {
focus?: 'descendant' | 'ancestor'
focus?: DefaultExtraEmpasisState['focus'] | 'descendant' | 'ancestor'
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/chart/tree/TreeSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
LabelOption,
OptionDataValue,
StatesOptionMixin,
OptionDataItemObject
OptionDataItemObject,
DefaultExtraEmpasisState
} from '../../util/types';
import List from '../../data/List';
import View from '../../coord/View';
Expand All @@ -52,7 +53,7 @@ export interface TreeSeriesStateOption {

interface ExtraStateOption {
emphasis?: {
focus?: 'ancestor' | 'descendant'
focus?: DefaultExtraEmpasisState['focus'] | 'ancestor' | 'descendant'
scale?: boolean
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/chart/treemap/TreemapSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
StatesOptionMixin,
OptionId,
OptionName,
DecalObject
DecalObject,
DefaultExtraEmpasisState
} from '../../util/types';
import GlobalModel from '../../model/Global';
import { LayoutRect } from '../../util/layout';
Expand Down Expand Up @@ -78,7 +79,7 @@ interface TreemapSeriesCallbackDataParams extends CallbackDataParams {

interface ExtraStateOption {
emphasis?: {
focus?: 'descendant' | 'ancestor'
focus?: DefaultExtraEmpasisState['focus'] | 'descendant' | 'ancestor'
}
}

Expand Down Expand Up @@ -540,7 +541,8 @@ function setDefault(levels: TreemapSeriesLevelOption[], ecModel: GlobalModel) {
}

levels = levels || [];
let hasColorDefine, hasDecalDefine;
let hasColorDefine;
let hasDecalDefine;
zrUtil.each(levels, function (levelDefine) {
const model = new Model(levelDefine);
const modelColor = model.get('color');
Expand Down
5 changes: 3 additions & 2 deletions src/echarts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ class ECharts extends Eventful {
// Can't dispatch action during rendering procedure
private _pendingActions: Payload[] = [];

// We use unkown here so ECEventProcessor, which may include many unexpected types won't be exposed in the types to developers.
protected _$eventProcessor: unknown;
// We use never here so ECEventProcessor will not been exposed.
// which may include many unexpected types won't be exposed in the types to developers.
protected _$eventProcessor: never;

private _disposed: boolean;

Expand Down
42 changes: 24 additions & 18 deletions src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,23 +1372,33 @@ export type BlurScope = 'coordinateSystem' | 'series' | 'global';
*/
export type InnerFocus = string | ArrayLike<number> | Dictionary<ArrayLike<number>>;

export interface StatesOptionMixin<StateOption = unknown, ExtraStateOpts extends {
emphasis?: any
export interface DefaultExtraStateOpts {
emphasis: any
select: any
blur: any
}

export interface DefaultExtraEmpasisState {
/**
* self: Focus self and blur all others.
* series: Focus series and blur all other series.
*/
focus?: 'none' | 'self' | 'series'
}

interface ExtraStateOptsBase {
emphasis?: {
focus?: string
},
select?: any
blur?: any
} = unknown> {
}

export interface StatesOptionMixin<StateOption, ExtraStateOpts extends ExtraStateOptsBase = DefaultExtraStateOpts> {
/**
* Emphasis states
*/
emphasis?: StateOption & {
/**
* self: Focus self and blur all others.
* series: Focus series and blur all other series.
*/
focus?: 'none' | 'self' | 'series' |
(unknown extends ExtraStateOpts['emphasis']['focus']
? never : ExtraStateOpts['emphasis']['focus'])

emphasis?: StateOption & ExtraStateOpts['emphasis'] & {
/**
* Scope of blurred element when focus.
*
Expand All @@ -1399,7 +1409,7 @@ export interface StatesOptionMixin<StateOption = unknown, ExtraStateOpts extends
* Default to be coordinate system.
*/
blurScope?: BlurScope
} & Omit<ExtraStateOpts['emphasis'], 'focus'>
}
/**
* Select states
*/
Expand All @@ -1410,11 +1420,7 @@ export interface StatesOptionMixin<StateOption = unknown, ExtraStateOpts extends
blur?: StateOption & ExtraStateOpts['blur']
}

export interface SeriesOption<StateOption=any, ExtraStateOpts extends {
emphasis?: any
select?: any
blur?: any
} = unknown> extends
export interface SeriesOption<StateOption=any, ExtraStateOpts extends ExtraStateOptsBase = DefaultExtraStateOpts> extends
ComponentOption,
AnimationOptionMixin,
ColorPaletteOptionMixin,
Expand Down

0 comments on commit 2086398

Please sign in to comment.