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

时间:2020-08-06 18:24:58

标签: javascript typescript types node-modules

我正在使用没有相关类型的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通过dts-gen -m symphony-api-client-node创建类型文件。当我将此文件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"]
}

symphony-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-client-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;
...

0 个答案:

没有答案