首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误:在Typescript中使用Thrift时,找不到名称‘Thrift

错误:在Typescript中使用Thrift时,找不到名称‘Thrift
EN

Stack Overflow用户
提问于 2018-12-13 14:12:18
回答 1查看 549关注 0票数 0

我想在Nodejs项目中使用Thrift和Typescript,这是我遇到的错误

代码语言:javascript
复制
src/gen-js/myService.d.ts:9:12 - error TS2503: Cannot find namespace 'Thrift'.

10     input: Thrift.TJSONProtocol;
              ~~~~~~
src/gen-js/myService.d.ts:10:1 - error TS2503: Cannot find namespace 'Thrift'.

11     output: Thrift.TJSONProtocol;
               ~~~~~~
error TS2304: Cannot find name 'Thrift'.

...(more of the same)

src/gen-js/myService_types.d.ts:198:32 - error TS2304: Cannot find name 'Thrift'.

198   class StoreException extends Thrift.TException {
                               ~~~~~~
...(more of the same)

我已经安装了@types/thrift并设置了我的tsconfig.json,如下所示

代码语言:javascript
复制
{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es2017",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "inlineSourceMap": true,
    "outDir": "dist",
    "alwaysStrict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*", "src/types/*"]
    },
    "lib": [
      "dom",
      "esnext"
    ]
  },
  "include": ["src/**/*"]
}

看起来很好,对吧?仍然会遇到错误。你知道如何成功构建它吗?

附注:我使用的是Typescript 3.2、Thrift v0.11和@types/thrift 0.10.7

EN

回答 1

Stack Overflow用户

发布于 2018-12-13 14:31:01

安装这些类型后,您仍然需要在引用它们之前导入它们。

编辑:

在查看了类型定义之后,它不是..理想的打字方式。如果使用通配符导入类型(第二个示例),则还有一个嵌套的Thrift命名空间

代码语言:javascript
复制
import { Thrift, TJSONProtocol } from 'thrift';

const protocol: TJSONProtocol = // instance;

class StoreException extends Thrift.TException {}

代码语言:javascript
复制
import * as Thrift from 'thrift';

const protocol: Thrift.TJSONProtocol = // instance;

class StoreException extends Thrift.Thrift.TException {}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53755917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档