简体   繁体   English

使用带有打字稿的apache thrift

[英]Using apache thrift with typescript

I generated .js and .d.ts files with the apache thrift compiler. 我用apache thrift编译器生成了.js和.d.ts文件。 How can I use this files in my existing Angular2/Typescript-Project? 如何在现有的Angular2 / Typescript-Project中使用这些文件? I tried to use 我试着用

///<reference path="./thrift.d.ts"/>
///<reference path="./Service.d.ts"/>

And

import Thrift = require("./thrift");
import Service = require("./Service")

If i use this four lines, the typescript compiler is not complaining, but "Thrift" is not defined when i want to use it. 如果我使用这四行,那么打字稿编译器就不会抱怨,但是当我想使用时,“Thrift”没有被定义。 thrift.js, Service.js and both .d.ts files are existing in the folder. thrift.js,Service.js和两个.d.ts文件都存在于该文件夹中。

Thank you very much! 非常感谢你!

您需要在index.html中手动引用thrift.js

yarn add @types/thrift 纱线添加@类型/节俭

import * as thrift from  'thrift';
...
var transport = thrift.TBufferedTransport;
var protocol = thrift.TBinaryProtocol;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM