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/11/07 06:46:33 UTC

[GitHub] [echarts] SuperRay3 edited a comment on issue #15527: typeScript 下 echarts.registerMap,提示错误,怎么解决

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