打字稿自定义类型定义文件不起作用

时间:2020-10-16 16:51:36

标签: typescript typescript-typings

我已经看到数千个类似问题的答案,但没有一个对我有用。我试图通过创建我自己的.d.ts文件来使用没有打字稿类型定义的npm模块。我总是收到以下错误:Could not find a declaration file for module 'aws-elasticsearch-connector'.

文件结构

enter image description here

tsconfig.json

{
  "include": [
    "src"
  ],
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true
  }
}

aws-elasticsearch-connector.d.ts

declare module 'aws-elasticsearch-connector';

index.ts

import * as AWS from 'aws-sdk'
import { Client } from '@elastic/elasticsearch'
import { createAwsElasticsearchConnector } from 'aws-elasticsearch-connector'

1 个答案:

答案 0 :(得分:0)

您能否尝试像这样在tsconfig.json中设置include选项:

"include": ["src/**/*"]

包含选项的文档:https://www.typescriptlang.org/tsconfig#include