我正在尝试使用thrift的Const
功能为我的模型创建存根数据。例如:
struct Book { 1: i32 id } struct Author { 1: Book book } const Book bookEx1 = { // example instance of Book 'id': 1 } const Author AuthorEx1 = { /// example instance of Author //'book': { 'id': 1 } // This is a copy from above, but works well 'book': BookEx1 // this doesn't work, see below }
以上示例在编译时会抛出错误:
$ thrift -v -gen js:ts model.thrift Scanning model.thrift for includes Parsing model.thrift for types [FAILURE:model.thrift:17] type error: const "AuthorEx1.book" was declared as struct/xception
问题:我想通过之前定义的结构(例如bookEx1)引用其他定义的const结构,而不是展平值。我怎么能这样做?
我使用Thrift 0.9.2。