You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2020/07/17 11:39:03 UTC

[incubator-echarts] 04/16: ts: remove "any" from type ECUnitOption (which causes "any" spread).

This is an automated email from the ASF dual-hosted git repository.

sushuang pushed a commit to branch remove-component
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit 18c21561ff727e9c1795972a199c015ac63df522
Author: 100pah <su...@gmail.com>
AuthorDate: Wed Jul 8 22:53:48 2020 +0800

    ts: remove "any" from type ECUnitOption (which causes "any" spread).
---
 src/chart/bar/BarView.ts                   |  8 +++++---
 src/chart/bar/PictorialBarView.ts          |  2 +-
 src/chart/parallel/ParallelSeries.ts       |  4 +++-
 src/component/axisPointer.ts               |  6 +++---
 src/component/brush/preprocessor.ts        | 12 ++++++------
 src/component/toolbox/feature/Brush.ts     |  2 +-
 src/component/toolbox/feature/DataView.ts  |  6 +++---
 src/component/toolbox/feature/DataZoom.ts  |  9 +++------
 src/component/toolbox/feature/MagicType.ts | 11 ++++++-----
 src/coord/parallel/parallelPreprocessor.ts |  6 ++++--
 src/echarts.ts                             |  5 +++--
 src/model/Component.ts                     |  2 ++
 src/model/Model.ts                         |  2 +-
 src/model/mixin/textStyle.ts               |  2 +-
 src/util/types.ts                          |  8 +++++++-
 15 files changed, 49 insertions(+), 36 deletions(-)

diff --git a/src/chart/bar/BarView.ts b/src/chart/bar/BarView.ts
index d7dc1e1..6a29190 100644
--- a/src/chart/bar/BarView.ts
+++ b/src/chart/bar/BarView.ts
@@ -47,7 +47,9 @@ import {
     OrdinalSortInfo,
     Payload,
     OrdinalNumber,
-    ParsedValue
+    ParsedValue,
+    ECUnitOption,
+    AnimationOptionMixin
 } from '../../util/types';
 import BarSeriesModel, { BarSeriesOption, BarDataItemOption } from './BarSeries';
 import type Axis2D from '../../coord/cartesian/Axis2D';
@@ -708,7 +710,7 @@ function removeRect(
         style: {
             opacity: 0
         }
-    }, animationModel, dataIndex, function () {
+    }, animationModel as Model<AnimationOptionMixin>, dataIndex, function () {
         el.parent && el.parent.remove(el);
     });
 }
@@ -724,7 +726,7 @@ function removeSector(
         style: {
             opacity: 0
         }
-    }, animationModel, dataIndex, function () {
+    }, animationModel as Model<AnimationOptionMixin>, dataIndex, function () {
         el.parent && el.parent.remove(el);
     });
 }
diff --git a/src/chart/bar/PictorialBarView.ts b/src/chart/bar/PictorialBarView.ts
index 48a7774..d7ee71c 100644
--- a/src/chart/bar/PictorialBarView.ts
+++ b/src/chart/bar/PictorialBarView.ts
@@ -222,7 +222,7 @@ class PictorialBarView extends ChartView {
         if (ecModel.get('animation')) {
             if (data) {
                 data.eachItemGraphicEl(function (bar: PictorialBarElement) {
-                    removeBar(data, graphic.getECData(bar).dataIndex, ecModel, bar);
+                    removeBar(data, graphic.getECData(bar).dataIndex, ecModel as Model<AnimationOptionMixin>, bar);
                 });
             }
         }
diff --git a/src/chart/parallel/ParallelSeries.ts b/src/chart/parallel/ParallelSeries.ts
index 1fd5c8f..8dbe52b 100644
--- a/src/chart/parallel/ParallelSeries.ts
+++ b/src/chart/parallel/ParallelSeries.ts
@@ -32,7 +32,7 @@ import {
  } from '../../util/types';
 import GlobalModel from '../../model/Global';
 import List from '../../data/List';
-import { ParallelActiveState } from '../../coord/parallel/AxisModel';
+import { ParallelActiveState, ParallelAxisOption } from '../../coord/parallel/AxisModel';
 import Parallel from '../../coord/parallel/Parallel';
 import Source from '../../data/Source';
 import ParallelModel from '../../coord/parallel/ParallelModel';
@@ -72,6 +72,8 @@ export interface ParallelSeriesOption extends
     realtime?: boolean;
     tooltip?: SeriesTooltipOption;
 
+    parallelAxisDefault?: ParallelAxisOption;
+
     emphasis?: {
         label?: LabelOption;
         lineStyle?: LineStyleOption;
diff --git a/src/component/axisPointer.ts b/src/component/axisPointer.ts
index 2e0b9e7..1b68850 100644
--- a/src/component/axisPointer.ts
+++ b/src/component/axisPointer.ts
@@ -36,15 +36,15 @@ ComponentModel.registerClass(AxisPointerModel);
 echarts.registerPreprocessor(function (option) {
     // Always has a global axisPointerModel for default setting.
     if (option) {
-        (!option.axisPointer || option.axisPointer.length === 0)
+        (!option.axisPointer || (option.axisPointer as []).length === 0)
             && (option.axisPointer = {});
 
-        const link = option.axisPointer.link;
+        const link = (option.axisPointer as any).link;
         // Normalize to array to avoid object mergin. But if link
         // is not set, remain null/undefined, otherwise it will
         // override existent link setting.
         if (link && !zrUtil.isArray(link)) {
-            option.axisPointer.link = [link];
+            (option.axisPointer as any).link = [link];
         }
     }
 });
diff --git a/src/component/brush/preprocessor.ts b/src/component/brush/preprocessor.ts
index 8184ed6..2c49e2a 100644
--- a/src/component/brush/preprocessor.ts
+++ b/src/component/brush/preprocessor.ts
@@ -21,14 +21,14 @@
 import * as zrUtil from 'zrender/src/core/util';
 import { ECUnitOption, Dictionary } from '../../util/types';
 import { BrushOption, BrushToolboxIconType } from './BrushModel';
+import { ToolboxOption } from '../toolbox/ToolboxModel';
+import { ToolboxBrushFeatureOption } from '../toolbox/feature/Brush';
+import { normalizeToArray } from '../../util/model';
 
 const DEFAULT_TOOLBOX_BTNS: BrushToolboxIconType[] = ['rect', 'polygon', 'keep', 'clear'];
 
 export default function (option: ECUnitOption, isNew: boolean): void {
-    let brushComponents = option && option.brush;
-    if (!zrUtil.isArray(brushComponents)) {
-        brushComponents = brushComponents ? [brushComponents] : [];
-    }
+    const brushComponents = normalizeToArray(option ? option.brush : []);
 
     if (!brushComponents.length) {
         return;
@@ -45,7 +45,7 @@ export default function (option: ECUnitOption, isNew: boolean): void {
         }
     });
 
-    let toolbox = option && option.toolbox;
+    let toolbox: ToolboxOption = option && option.toolbox;
 
     if (zrUtil.isArray(toolbox)) {
         toolbox = toolbox[0];
@@ -56,7 +56,7 @@ export default function (option: ECUnitOption, isNew: boolean): void {
     }
 
     const toolboxFeature = (toolbox.feature || (toolbox.feature = {}));
-    const toolboxBrush = toolboxFeature.brush || (toolboxFeature.brush = {});
+    const toolboxBrush = (toolboxFeature.brush || (toolboxFeature.brush = {})) as ToolboxBrushFeatureOption;
     const brushTypes = toolboxBrush.type || (toolboxBrush.type = []);
 
     brushTypes.push.apply(brushTypes, brushComponentSpecifiedBtns);
diff --git a/src/component/toolbox/feature/Brush.ts b/src/component/toolbox/feature/Brush.ts
index d39fbdb..984fa33 100644
--- a/src/component/toolbox/feature/Brush.ts
+++ b/src/component/toolbox/feature/Brush.ts
@@ -36,7 +36,7 @@ const ICON_TYPES = ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'] as con
 
 type IconType = typeof ICON_TYPES[number];
 
-interface ToolboxBrushFeatureOption extends ToolboxFeatureOption {
+export interface ToolboxBrushFeatureOption extends ToolboxFeatureOption {
     type?: IconType[]
     icon?: {[key in IconType]?: string}
     title?: {[key in IconType]?: string}
diff --git a/src/component/toolbox/feature/DataView.ts b/src/component/toolbox/feature/DataView.ts
index 5a855ac..690f7d4 100644
--- a/src/component/toolbox/feature/DataView.ts
+++ b/src/component/toolbox/feature/DataView.ts
@@ -270,15 +270,15 @@ function parseContents(str: string, blockMetaList: SeriesGroupMeta[]) {
 
             if (blockMeta) {
                 newOption[axisKey] = newOption[axisKey] || [];
-                newOption[axisKey][blockMeta.axisIndex] = {
+                (newOption[axisKey] as any)[blockMeta.axisIndex] = {
                     data: result.categories
                 };
-                newOption.series = newOption.series.concat(result.series);
+                newOption.series = (newOption.series as SeriesOption[]).concat(result.series);
             }
         }
         else {
             const result = parseListContents(block);
-            newOption.series.push(result);
+            (newOption.series as SeriesOption[]).push(result);
         }
     });
     return newOption;
diff --git a/src/component/toolbox/feature/DataZoom.ts b/src/component/toolbox/feature/DataZoom.ts
index 5a2da53..ec2bed2 100644
--- a/src/component/toolbox/feature/DataZoom.ts
+++ b/src/component/toolbox/feature/DataZoom.ts
@@ -39,9 +39,9 @@ import ExtensionAPI from '../../../ExtensionAPI';
 import { Payload, ECUnitOption, Dictionary } from '../../../util/types';
 import Cartesian2D from '../../../coord/cartesian/Cartesian2D';
 import CartesianAxisModel from '../../../coord/cartesian/AxisModel';
-import DataZoomModel from '../../dataZoom/DataZoomModel';
+import DataZoomModel, { DataZoomOption } from '../../dataZoom/DataZoomModel';
 import { DataZoomPayloadBatchItem } from '../../dataZoom/helper';
-import { ModelFinderObject, ModelFinderIndexQuery } from '../../../util/model';
+import { ModelFinderObject, ModelFinderIndexQuery, normalizeToArray } from '../../../util/model';
 import { ToolboxOption } from '../ToolboxModel';
 
 const dataZoomLang = lang.toolbox.dataZoom;
@@ -301,10 +301,7 @@ echarts.registerPreprocessor(function (option: ECUnitOption) {
         return;
     }
 
-    let dataZoomOpts = option.dataZoom || (option.dataZoom = []);
-    if (!zrUtil.isArray(dataZoomOpts)) {
-        option.dataZoom = dataZoomOpts = [dataZoomOpts];
-    }
+    const dataZoomOpts = option.dataZoom = normalizeToArray(option.dataZoom) as DataZoomOption[];
 
     let toolboxOpt = option.toolbox as ToolboxOption;
     if (toolboxOpt) {
diff --git a/src/component/toolbox/feature/MagicType.ts b/src/component/toolbox/feature/MagicType.ts
index f05996b..2dfd038 100644
--- a/src/component/toolbox/feature/MagicType.ts
+++ b/src/component/toolbox/feature/MagicType.ts
@@ -108,7 +108,7 @@ class MagicType extends ToolboxFeature<ToolboxMagicTypeFeatureOption> {
             if (newSeriesOpt) {
                 // PENDING If merge original option?
                 zrUtil.defaults(newSeriesOpt, seriesModel.option);
-                newOption.series.push(newSeriesOpt);
+                (newOption.series as SeriesOption[]).push(newSeriesOpt);
             }
             // Modify boundaryGap
             const coordSys = seriesModel.coordinateSystem;
@@ -126,9 +126,9 @@ class MagicType extends ToolboxFeature<ToolboxMagicTypeFeatureOption> {
 
                     newOption[axisType] = newOption[axisType] || [];
                     for (let i = 0; i <= axisIndex; i++) {
-                        newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
+                        (newOption[axisType] as any)[axisIndex] = (newOption[axisType] as any)[axisIndex] || {};
                     }
-                    newOption[axisType][axisIndex].boundaryGap = type === 'bar';
+                    (newOption[axisType] as any)[axisIndex].boundaryGap = type === 'bar';
                 }
             }
         };
@@ -155,8 +155,9 @@ class MagicType extends ToolboxFeature<ToolboxMagicTypeFeatureOption> {
         let newTitle;
         // Change title of stack
         if (type === 'stack') {
-            const isStack = newOption.series && newOption.series[0]
-                && newOption.series[0].stack === INNER_STACK_KEYWORD;
+            const seriesOptions = newOption.series as (SeriesOption & { stack: string })[];
+            const isStack = seriesOptions && seriesOptions[0]
+                && seriesOptions[0].stack === INNER_STACK_KEYWORD;
             newTitle = isStack
                 ? zrUtil.merge({ stack: magicTypeLang.title.tiled }, magicTypeLang.title)
                 : zrUtil.clone(magicTypeLang.title);
diff --git a/src/coord/parallel/parallelPreprocessor.ts b/src/coord/parallel/parallelPreprocessor.ts
index d456ee2..fda2a2f 100644
--- a/src/coord/parallel/parallelPreprocessor.ts
+++ b/src/coord/parallel/parallelPreprocessor.ts
@@ -21,6 +21,8 @@
 import * as zrUtil from 'zrender/src/core/util';
 import * as modelUtil from '../../util/model';
 import { ECUnitOption, SeriesOption } from '../../util/types';
+import { ParallelAxisOption } from './AxisModel';
+import { ParallelSeriesOption } from '../../chart/parallel/ParallelSeries';
 
 export default function (option: ECUnitOption): void {
     createParallelIfNeeded(option);
@@ -54,7 +56,7 @@ function createParallelIfNeeded(option: ECUnitOption): void {
  * @inner
  */
 function mergeAxisOptionFromParallel(option: ECUnitOption): void {
-    const axes = modelUtil.normalizeToArray(option.parallelAxis);
+    const axes = modelUtil.normalizeToArray(option.parallelAxis) as ParallelAxisOption[];
 
     zrUtil.each(axes, function (axisOption) {
         if (!zrUtil.isObject(axisOption)) {
@@ -62,7 +64,7 @@ function mergeAxisOptionFromParallel(option: ECUnitOption): void {
         }
 
         const parallelIndex = axisOption.parallelIndex || 0;
-        const parallelOption = modelUtil.normalizeToArray(option.parallel)[parallelIndex];
+        const parallelOption = modelUtil.normalizeToArray(option.parallel)[parallelIndex] as ParallelSeriesOption;
 
         if (parallelOption && parallelOption.parallelAxisDefault) {
             zrUtil.merge(axisOption, parallelOption.parallelAxisDefault, false);
diff --git a/src/echarts.ts b/src/echarts.ts
index 3cdd73f..581bf53 100644
--- a/src/echarts.ts
+++ b/src/echarts.ts
@@ -62,7 +62,8 @@ import {
     ZRColor,
     ComponentMainType,
     ComponentSubType,
-    ZRElementEvent
+    ZRElementEvent,
+    ColorString
 } from './util/types';
 import Displayable from 'zrender/src/graphic/Displayable';
 import IncrementalDisplayable from 'zrender/src/graphic/IncrementalDisplayable';
@@ -1375,7 +1376,7 @@ class ECharts extends Eventful {
 
                 // In IE8
                 if (!env.canvasSupported) {
-                    const colorArr = colorTool.parse(backgroundColor);
+                    const colorArr = colorTool.parse(backgroundColor as ColorString);
                     backgroundColor = colorTool.stringify(colorArr, 'rgb');
                     if (colorArr[3] === 0) {
                         backgroundColor = 'transparent';
diff --git a/src/model/Component.ts b/src/model/Component.ts
index e9c89ce..74fccf0 100644
--- a/src/model/Component.ts
+++ b/src/model/Component.ts
@@ -290,6 +290,8 @@ class ComponentModel<Opt extends ComponentOption = ComponentOption> extends Mode
 
     static registerClass: ClassManager['registerClass'];
 
+    static hasClass: ClassManager['hasClass'];
+
     static registerSubTypeDefaulter: componentUtil.SubTypeDefaulterManager['registerSubTypeDefaulter'];
 }
 
diff --git a/src/model/Model.ts b/src/model/Model.ts
index e9cf064..bfeac1c 100644
--- a/src/model/Model.ts
+++ b/src/model/Model.ts
@@ -32,7 +32,7 @@ import {ItemStyleMixin} from './mixin/itemStyle';
 import GlobalModel from './Global';
 import { ModelOption } from '../util/types';
 import { Dictionary } from 'zrender/src/core/types';
-import { mixin, clone, merge, extend, isFunction } from 'zrender/src/core/util';
+import { mixin, clone, merge } from 'zrender/src/core/util';
 
 // Since model.option can be not only `Dictionary` but also primary types,
 // we do this conditional type to avoid getting type 'never';
diff --git a/src/model/mixin/textStyle.ts b/src/model/mixin/textStyle.ts
index 907bba4..9483bc2 100644
--- a/src/model/mixin/textStyle.ts
+++ b/src/model/mixin/textStyle.ts
@@ -24,7 +24,7 @@ import ZRText from 'zrender/src/graphic/Text';
 
 const PATH_COLOR = ['textStyle', 'color'] as const;
 
-type LabelFontOption = Pick<LabelOption, 'fontStyle' | 'fontWeight' | 'fontSize' | 'fontFamily'>;
+export type LabelFontOption = Pick<LabelOption, 'fontStyle' | 'fontWeight' | 'fontSize' | 'fontFamily'>;
 type LabelRectRelatedOption = Pick<LabelOption,
     'align' | 'verticalAlign' | 'padding' | 'lineHeight' | 'baseline' | 'rich'
 > & LabelFontOption;
diff --git a/src/util/types.ts b/src/util/types.ts
index 3125df8..a99219c 100644
--- a/src/util/types.ts
+++ b/src/util/types.ts
@@ -353,8 +353,14 @@ export type ECUnitOption = {
     baseOption?: never
     options?: never
     media?: never
+
     timeline?: ComponentOption | ComponentOption[]
-    [key: string]: ComponentOption | ComponentOption[] | Dictionary<any> | any
+    backgroundColor?: ZRColor
+    darkMode?: boolean | 'auto'
+    textStyle?: Pick<LabelOption, 'color' | 'fontStyle' | 'fontWeight' | 'fontSize' | 'fontFamily'>
+
+    [key: string]: ComponentOption | ComponentOption[] | Dictionary<unknown> | unknown
+
 } & AnimationOptionMixin & ColorPaletteOptionMixin;
 
 /**


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org