iRON5 / echarts-ts-describer

Helps generate huge amount of echarts definitions
MIT License
6 stars 1 forks source link

TypeScript 声明文件 SeriesBar.markPoint.data 类型声明有误 #2

Open NickeyLin opened 5 years ago

NickeyLin commented 5 years ago

Issue Details

TypeScript 声明文件 SeriesBar.markPoint.data 类型声明有误。而且感觉整个声明文件很乱,有些应该相同的类型,因为在不同的series中,类型却不一样,比如fontWeight,有些地方声明为: 'normal' | 'bold' | 'bolder' | 'lighter' | 100 | 200 | 300 | 400,有些地方却只是简单的 string

Expected Behavior

在TypeScript中能正确使用柱形图的markPoint,并且希望TypeScript声明更加规范一点。

Current Behavior

下面语句会报错

get barSerie(): EChartOption.SeriesBar {
    return {
      name,
      data: this.data.map(item => ({ name: item.name, value: item.value, itemStyle: { ...item.barItemStyle } })),
      markPoint: {
        ...this.markPoint,
        data: [
          {
            name: '最大值',
            type: 'max'
          }
        ]
      }
    };
  }

错误信息

属性“data”的类型不兼容。
    类型“{ name: string; type: string; }[]”与类型“{ name?: string | undefined; type?: string | undefined; valueIndex?: number | undefined; valueDim?: string | undefined; coord?: any[] | undefined; x?: number | undefined; y?: number | undefined; ... 7 more ...; label?: { ...; } | undefined; }”不具有相同的属性。

markPoint.data 应该是数组类型,但是声明文件里面却是object。

image

Online Example

Topics

Environment

iRON5 commented 5 years ago

Hi, @NickeyLin First of all thank you for the issue.

The problem is known and it is related with inconsistent documentation in documentation at the moment of typings generation.

This tool is trying to retrieve types from the content of fields as they are more verbose and correct. For example if fontWeight can contain only values 'normal' | 'bold' | 'bolder' | 'lighter' | 100 | 200 | 300 | 400 so this type will be more correct than just 'string'.

However because of fields' content descriptions are different between series so it is very hard to parse all cases. If the tool cannot correctly parse content of some field than it will use the type placed beside the rule name.

Actually this tool works tricky way trying to parse data not from the source. Maybe the source of the docs is more consistent and generated result will be much better. I'll write here details on finish the investigation.