AtarisMio commented on issue #84: 处理hashmap时会因key的类型而无法通过ts类型校验
URL: https://github.com/apache/dubbo-js/pull/84#issuecomment-548708919
 
 
   @creasy2010 
   
   ```
   import {AcceptRuleItem} from './AcceptRuleItem';
   import java from 'js-to-java';
   
   export interface IAcceptRuleDto {
     cityName?: string;
     cateId?: number;
     cityId?: number;
     cateName?: string;
     ruleMap?: {[name: number]: AcceptRuleItem};
   }
   
   export class AcceptRuleDto {
     cityName?: string;
     cateId?: number;
     cityId?: number;
     cateName?: string;
     ruleMap?: {[name: number]: AcceptRuleItem};
   
     constructor(params: IAcceptRuleDto) {
       this.cityName = params.cityName;
       this.cateId = params.cateId;
       this.cityId = params.cityId;
       this.cateName = params.cateName;
       this.ruleMap = params.ruleMap;
     }
   
     __fields2java() {
       let ruleMapMapTransfer = new Map();
       for (let mapKey in this.ruleMap) {
         ruleMapMapTransfer.set(
           java.Long(mapKey),
           this.ruleMap[mapKey] ? this.ruleMap[mapKey].__fields2java() : null,
         );
       }
       return {
         $class: 'com.qf58.biz.dto.AcceptRuleDto',
         $: {
           cityName: java.String(this.cityName),
           cateId: java.Long(this.cateId),
           cityId: java.Long(this.cityId),
           cateName: java.String(this.cateName),
           ruleMap: java.HashMap(ruleMapMapTransfer),
         },
       };
     }
   }
   //generate by interpret-cli dubbo2.js
   ```
   
   比如这段代码中
   
   java.Long(mapKey)参数需要是number,但是ts做for in的时候key的type会被转化成string,然后这里就会报错
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to