【问题标题】:TypeScript Error Cannot find name on 'SyncClient' TwilioTypeScript 错误在“SyncClient”Twilio 上找不到名称
【发布时间】:2017-11-21 08:12:49
【问题描述】:

我正在创建一个离子应用程序,每次我尝试通过 npm install 在我的项目中使用库 twilio-chat 时,我总是在 .d.ts 文件上遇到错误

在我的提供商中导入:

import { Client } from "twilio-chat";

错误:

似乎.d.ts 文件不知道在哪里寻找他们需要的依赖模块。它与打字稿的类型有关吗?我对打字稿很陌生。

但是当我尝试使用cdn 时,它工作得非常好。

我正在使用

  • ionic: "3.18.0"
  • typescript: "2.2.1"
  • twlio-chat: "1.2.1"

更新:我能够修复 SyncClient 和 Emc Client,方法是精确映射 .d.ts 文件。唯一的问题是 twilio 依赖项没有 .d.ts 文件,例如 twilio-transporttwilsocktwilio-notifications

tsconfig.json 包含:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5",
    "baseUrl": ".",
    "paths": {
      "twilio-sync": ["node_modules/twilio-sync/lib"],
      "twilio-ems-client": ["node_modules/twilio-ems-client/lib"]
    }
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

TIA

【问题讨论】:

    标签: javascript typescript ionic2 twilio


    【解决方案1】:

    你如何编译打字稿文件?如果您使用 tsconfig.json,请确保它使用“moduleResolution”:“node”,并且可以从上层目录中找到 node_modules。也许你想看这个:https://www.typescriptlang.org/docs/handbook/module-resolution.html#node

    【讨论】:

    • Hi Anti 通过在我的 tsconfig 上映射 SyncClient 我能够修复它。我现在唯一的问题是其他 node_modules 没有.d.ts 文件,我需要为它们制作一个吗?谢谢
    【解决方案2】:

    这里是 Twilio 开发人员宣传员。让我看看能不能帮到你 :) 从技术上讲,这应该是开箱即用的,因为 twilio-synctwilio-chat 库都是用 TypeScript 编写的。您能否发布您的 tsconfig.json 以及您已安装的完整依赖项列表,以便我们查看?

    一般来说,您必须为任何不提供其自己的类型的模块安装类型。

    干杯, 多米尼克

    【讨论】:

      猜你喜欢
      • 2016-01-24
      • 2020-07-10
      • 2017-06-23
      • 2021-01-27
      • 2016-11-12
      • 2021-09-24
      • 2020-01-19
      • 1970-01-01
      相关资源
      最近更新 更多