0
回答
thrift生成的ts文件有问题?该如何解决
开发十年,就只剩下这套Java开发体系了   

我的hello.thrift文件内容如下

service Hello {
  string say(1: string name);
}

我用如下命令生成相关的typescript脚本,官方也是这样介绍的,官方地址http://thrift.apache.org/lib/js

thrift --gen js:ts  hello.thrift

但是生成的文件却是下面这样的错误文件,没有引用相关的依赖包,我该怎么办?求大神指点

1、helo.d.ts

// // Autogenerated by Thrift Compiler (0.9.3) // // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING //   
declare class HelloClient {
  input: Thrift.TJSONProtocol;
  output: Thrift.TJSONProtocol;
  seqid: number; constructor(input: Thrift.TJSONProtocol, output?: Thrift.TJSONProtocol); say(name: string): string; say(name: string, callback: Function): void;
}

2、helo.js

// // Autogenerated by Thrift Compiler (0.9.3) // // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING //   //HELPER FUNCTIONS AND STRUCTURES  Hello_say_args = function(args) { this.name = null; if (args) { if (args.name !== undefined && args.name !== null) { this.name = args.name;
    }
  }
}; Hello_say_args.prototype = {}; Hello_say_args.prototype.read = function(input) { input.readStructBegin(); while (true)
  { var ret = input.readFieldBegin(); var fname = ret.fname; var ftype = ret.ftype; var fid = ret.fid; if (ftype == Thrift.Type.STOP) { break;
    } switch (fid)
    { case 1: if (ftype == Thrift.Type.STRING) { this.name = input.readString().value;
      } else { input.skip(ftype);
      } break; case 0: input.skip(ftype); break; default: input.skip(ftype);
    } input.readFieldEnd();
  } input.readStructEnd(); return;
}; Hello_say_args.prototype.write = function(output) { output.writeStructBegin('Hello_say_args'); if (this.name !== null && this.name !== undefined) { output.writeFieldBegin('name', Thrift.Type.STRING, 1); output.writeString(this.name); output.writeFieldEnd();
  } output.writeFieldStop(); output.writeStructEnd(); return;
}; Hello_say_result = function(args) { this.success = null; if (args) { if (args.success !== undefined && args.success !== null) { this.success = args.success;
    }
  }
}; Hello_say_result.prototype = {}; Hello_say_result.prototype.read = function(input) { input.readStructBegin(); while (true)
  { var ret = input.readFieldBegin(); var fname = ret.fname; var ftype = ret.ftype; var fid = ret.fid; if (ftype == Thrift.Type.STOP) { break;
    } switch (fid)
    { case 0: if (ftype == Thrift.Type.STRING) { this.success = input.readString().value;
      } else { input.skip(ftype);
      } break; case 0: input.skip(ftype); break; default: input.skip(ftype);
    } input.readFieldEnd();
  } input.readStructEnd(); return;
}; Hello_say_result.prototype.write = function(output) { output.writeStructBegin('Hello_say_result'); if (this.success !== null && this.success !== undefined) { output.writeFieldBegin('success', Thrift.Type.STRING, 0); output.writeString(this.success); output.writeFieldEnd();
  } output.writeFieldStop(); output.writeStructEnd(); return;
}; HelloClient = function(input, output) { this.input = input; this.output = (!output) ? input : output; this.seqid = 0;
}; HelloClient.prototype = {}; HelloClient.prototype.say = function(name, callback) { this.send_say(name, callback); if (!callback) { return this.recv_say();
  }
}; HelloClient.prototype.send_say = function(name, callback) { this.output.writeMessageBegin('say', Thrift.MessageType.CALL, this.seqid); var args = new Hello_say_args();
  args.name = name;
  args.write(this.output); this.output.writeMessageEnd(); if (callback) { var self = this; this.output.getTransport().flush(true, function() { var result = null; try {
        result = self.recv_say();
      } catch (e) {
        result = e;
      } callback(result);
    });
  } else { return this.output.getTransport().flush();
  }
}; HelloClient.prototype.recv_say = function() { var ret = this.input.readMessageBegin(); var fname = ret.fname; var mtype = ret.mtype; var rseqid = ret.rseqid; if (mtype == Thrift.MessageType.EXCEPTION) { var x = new Thrift.TApplicationException();
    x.read(this.input); this.input.readMessageEnd(); throw x;
  } var result = new Hello_say_result();
  result.read(this.input); this.input.readMessageEnd(); if (null !== result.success) { return result.success;
  } throw 'say failed: unknown result';
};
3、helo_types.d.ts 和helo_types.js均为空文件

求大神解决,先谢谢了!


举报
yqsailor
发帖于2年前 0回/274阅
顶部