打字稿:使用dts-gen后找不到模块的声明文件

Typescript: could not find a declaration file for module after using dts-gen

我正在使用一个没有关联类型的 npm 包 https://github.com/SymphonyPlatformSolutions/symphony-api-client-node

目录结构

node_modules
  symphony-api-client-node/
    lib
      ...
src
  symphony-adapter.ts
package.json
tsconfig.json

我试图通过 dts-gen -m symphony-api-client-node 使用 dts-gen 创建类型文件。当我将此文件 symphony-api-client-node.d.ts 添加到 src 时,我仍然收到模块 symphony-api-client-node.

没有声明文件的错误

基于 https://www.typescriptlang.org/docs/handbook/module-resolution.html#how-typescript-resolves-modules,它应该会看到 src/symphony-api-client-node.d.ts 文件并使用它 - 我在这里遗漏了什么吗?

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "allowJs": true,
        "esModuleInterop": true,
        "target": "es2017",
        "noImplicitAny": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "removeComments": true,
        "jsx": "react"
    },
    "include": ["src/**/*", "config/*"],
    "exclude": ["./node_modules", "**/tests"]
}

交响乐-adapter.ts

import Symphony from 'symphony-api-client-node';

class Adapter {
  constructor(symphony: Symphony){
    this.symphonyBase = symphony;
  }
}

错误:

src/SymphonyAdapter.ts:3:22 - error TS7016: Could not find a declaration file for module 'symphony-api-client-node'. 'path/node_modules/symphony-api-client-node/index.js' implicitly has an 'any' type.
  Try `npm install @types/symphony-api-client-node` if it exists or add a new declaration (.d.ts) file containing `declare module 'symphony-api-client-node';`

3 import Symphony from 'symphony-api-client-node';

symphony-api-客户端-node.d.ts

/** Declaration file generated by dts-gen */

export function authenticateBot(SymConfig: any): any;

export function authenticateExtApp(): any;

export function authenticateOboApp(): any;

export function createRoom(room: any, description: any, keywords: any, membersCanInvite: any, discoverable: any, anyoneCanJoin: any, readOnly: any, copyProtected: any, crossPod: any, viewHistory: any): any;

export function createSignal(name: any, query: any, visibleOnProfile: any, companyWide: any, sessionToken: any): any;
...

包装生成的symphony-api-client-node.d.ts文件的内容
declare module "symphony-api-client-node" { }

例如:symphony-api-client-node.d.ts

declare module "symphony-api-client-node" {
  export function acceptConnectionRequest(userId: any, sessionToken: any): void;
  export function activateRoom(streamId: any): void;
  export function addMemberToRoom(streamId: any, userId: any): any;
  ...
}

请注意,dts-gen 是一个起点;您将需要做一些工作来修复类型(dts-gen 的自述文件也说了这么多)。例如,虽然 symphony-api-client-node return 中的许多导出函数承诺,但生成的 .d.ts 文件将指示 return 类型 any 大多数(如果不是全部的话)他们。