You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2021/08/13 08:58:09 UTC
[GitHub] [echarts] liujiaang opened a new issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
liujiaang opened a new issue #15527:
URL: https://github.com/apache/echarts/issues/15527
### Version
5.1.2
### Steps to reproduce
import * as echarts from 'echarts/core';
import chinaMap from './china.json';
echarts.registerMap('china', chinaMap);
提示报错 类型“{ type: string; features: ({ type: string; properties: { id: string; size: string; name: string; cp: number[]; childNum: number; }; geometry: { type: string; coordinates: number[][][]; }; } | { type: string; properties: { ...; }; geometry: { ...; }; })[]; }”的参数不能赋给类型“MapInput | GeoJSONSourceInput”的参数。
不能将类型“{ type: string; features: ({ type: string; properties: { id: string; size: string; name: string; cp: number[]; childNum: number; }; geometry: { type: string; coordinates: number[][][]; }; } | { type: string; properties: { ...; }; geometry: { ...; }; })[]; }”分配给类型“GeoJSONCompressed”。
属性“type”的类型不兼容。
不能将类型“string”分配给类型“"FeatureCollection"”。
### What is expected?
怎么才能不报错
### What is actually happening?
希望知道引入什么类型会不报错
<!-- This issue is generated by echarts-issue-helper. DO NOT REMOVE -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] echarts-bot[bot] commented on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
Posted by GitBox <gi...@apache.org>.
echarts-bot[bot] commented on issue #15527:
URL: https://github.com/apache/echarts/issues/15527#issuecomment-898299673
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] SuperRay3 edited a comment on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
Posted by GitBox <gi...@apache.org>.
SuperRay3 edited a comment on issue #15527:
URL: https://github.com/apache/echarts/issues/15527#issuecomment-962399027
I think it's not a mistake of echarts.
According to the prompt, we can find the main problem is "The type "string" cannot be assigned to the type ""FeatureCollection""". After that we can jump to the type declaration in which file name called `shared.d.ts` whose path is `echarts/types/dist/shared.d.ts`
If you regist map by using GeoJSON, the type were limited by `GeoJSONFeatureCollection` `GeoJSONFeature` and `GeoJSONGeometry`.
Inspect the data in own code was inferred to be string by typescript, but echarts declare it as a literal "FeatureCollection".
**Solution:**
Add `as const` assertions to the field which were defined as literal. For example:
```json
{
type: 'FeatureCollection' as const,
features: [
{
id: '710000',
type: 'Feature' as const,
geometry: {
type: 'MultiPolygon' as const,
coordinates: [
......
],
encodeOffsets: [
......
],
},
properties: { cp: [121.509062, 25.044332], name: '', childNum: 6 },
},
]
}
```
@Ovilia Is my solution correct?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] SuperRay3 commented on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
Posted by GitBox <gi...@apache.org>.
SuperRay3 commented on issue #15527:
URL: https://github.com/apache/echarts/issues/15527#issuecomment-962399027
I think it's not a mistake of echarts.
According to the prompt, we can find the main problem is "The type "string" cannot be assigned to the type ""FeatureCollection""". After that we can jump to the type declaration in which file name called `shared.d.ts` whose path is `echarts/types/dist/shared.d.ts`
If you regist map by using GeoJSON, the type were limited by `GeoJSONFeatureCollection` `GeoJSONFeature` and `GeoJSONGeometry`.
Inspect the data in own code was inferred to be string by typescript, but echarts declare it as a literal "FeatureCollection".
**Solution:**
Add `as const` assertions to the field which were defined as literal. For example:
```json
{
type: 'FeatureCollection' as const,
features: [
{
id: '710000',
type: 'Feature' as const,
geometry: {
type: 'MultiPolygon' as const,
coordinates: [
......
],
encodeOffsets: [
......
],
},
properties: { cp: [121.509062, 25.044332], name: '', childNum: 6 },
},
]
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] echarts-bot[bot] commented on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
Posted by GitBox <gi...@apache.org>.
echarts-bot[bot] commented on issue #15527:
URL: https://github.com/apache/echarts/issues/15527#issuecomment-898336310
This issue is labeled with `difficulty: easy`.
@liujiaang Would you like to debug it by yourself? This is a quicker way to get your problem fixed. Or you may wait for the community to fix.
Please have a look at [How to debug ECharts](https://github.com/apache/echarts/blob/master/CONTRIBUTING.md#how-to-debug-echarts) if you'd like to give a try. 🤓
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] xinghehaohan edited a comment on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
Posted by GitBox <gi...@apache.org>.
xinghehaohan edited a comment on issue #15527:
URL: https://github.com/apache/echarts/issues/15527#issuecomment-914160862
```ts
echarts.registerMap('china', (china) as any);
echarts.registerMap('world', (world) as any);
echarts.registerMap('USA', (usa) as any, {
Alaska: {
// 把阿拉斯加移到美国主大陆左下方
left: -143,
top: 50,
width: 15
},
Hawaii: {
left: -135, // 夏威夷
top: 24,
width: 5
}
});
```
### 加 (usa) as any 可以解决这个bug
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] xinghehaohan commented on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
Posted by GitBox <gi...@apache.org>.
xinghehaohan commented on issue #15527:
URL: https://github.com/apache/echarts/issues/15527#issuecomment-914160862
echarts.registerMap('china', (china) as any);
echarts.registerMap('world', (world) as any);
echarts.registerMap('USA',### (usa) as any, {
Alaska: {
// 把阿拉斯加移到美国主大陆左下方
left: -143,
top: 50,
width: 15
},
Hawaii: {
left: -135, // 夏威夷
top: 24,
width: 5
}
});
### 加 (usa) as any 可以解决这个bug
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] LiuJB0128 commented on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
Posted by GitBox <gi...@apache.org>.
LiuJB0128 commented on issue #15527:
URL: https://github.com/apache/echarts/issues/15527#issuecomment-1086542860
请问这个问题解决了吗
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] xinghehaohan edited a comment on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
Posted by GitBox <gi...@apache.org>.
xinghehaohan edited a comment on issue #15527:
URL: https://github.com/apache/echarts/issues/15527#issuecomment-914160862
echarts.registerMap('china', (china) as any);
echarts.registerMap('world', (world) as any);
echarts.registerMap('USA', (usa) as any, {
Alaska: {
// 把阿拉斯加移到美国主大陆左下方
left: -143,
top: 50,
width: 15
},
Hawaii: {
left: -135, // 夏威夷
top: 24,
width: 5
}
});
### 加 (usa) as any 可以解决这个bug
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[GitHub] [echarts] Ovilia commented on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决
Posted by GitBox <gi...@apache.org>.
Ovilia commented on issue #15527:
URL: https://github.com/apache/echarts/issues/15527#issuecomment-898336119
找一下对应的类型定义是哪里错了,然后提个 PR 吧
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org