我们正在以多种语言使用节俭生成的对象,但是我不知道如何在js / ts中实例化对象。
这是生成的ts模块Network_Test_types.d.ts:
//
// Autogenerated by Thrift Compiler (0.12.0)
//
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
//
declare module Rockit {
class TestObject {
stringValue: string;
constructor(args?: { stringValue: string; });
}
}
这是生成的节俭js源Network_Test_types.js:
//
// Autogenerated by Thrift Compiler (0.12.0)
//
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
//
if (typeof Rockit === 'undefined') {
Rockit = {};
}
Rockit.TestObject = function(args) {
this.stringValue = null;
if (args) {
if (args.stringValue !== undefined && args.stringValue !== null) {
this.stringValue = args.stringValue;
} else {
throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field stringValue is unset!');
}
}
};
Rockit.TestObject.prototype = {};
Rockit.TestObject.prototype.read = function(input) {
input.readStructBegin();
while (true) {
var ret = input.readFieldBegin();
var ftype = ret.ftype;
var fid = ret.fid;
if (ftype == Thrift.Type.STOP) {
break;
}
switch (fid) {
case 1:
if (ftype == Thrift.Type.STRING) {
this.stringValue = input.readString().value;
} else {
input.skip(ftype);
}
break;
case 0:
input.skip(ftype);
break;
default:
input.skip(ftype);
}
input.readFieldEnd();
}
input.readStructEnd();
return;
};
Rockit.TestObject.prototype.write = function(output) {
output.writeStructBegin('TestObject');
if (this.stringValue !== null && this.stringValue !== undefined) {
output.writeFieldBegin('stringValue', Thrift.Type.STRING, 1);
output.writeString(this.stringValue);
output.writeFieldEnd();
}
output.writeFieldStop();
output.writeStructEnd();
return;
};
我尝试将模块导入这样的组件
import { Rockit } from '../assets/gen-js/Network_Test_types';
但是angular查找的文件名为Network_Test_types.d.js,而不是扩展名为.ts的文件。
所以我的问题是a)我要导入什么,b)如何构造对象?