TypeScript:指定目录以查找模块类型定义 [英] TypeScript: Specify a directory to look for module type definitions

查看:80
本文介绍了TypeScript:指定目录以查找模块类型定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

我想在我的打字稿代码中使用一些javascript库,在npm中没有任何打字.因此,我自己编写了键入内容,并将其放在源代码树的 definitions 目录中.但是,我无法让打字稿在该目录中查找那些模块.

I want to use some javascript libraries in my typescript code for which there are no typings in npm. So I wrote the typings myself and put them in a definitions directory in my source tree. However, I could not get typescript to look in that directory for those modules.

我的目录结构如下:

+-node_modules
| |
| +-moduleA
| |
| +-moduleB
|
+-src
| |
| +-definitions
| | |
| | +-moduleA.d.ts
| | |
| | +-moduleB.d.ts
| |
| +-ts
|   |
|   + ... all typescript code ...
|
+-tsconfig.json

我尝试使用

  • include
  • 文件
  • typeRoots
  • 路径

但是没有一个起作用.

有人可以告诉我,如何获取打字稿以包括这些打字吗?

Can somebody tell me, how to get typescript to include those typings?

PS:为什么TypeScript模块的处理如此复杂??

PS: Why is the TypeScript module handling so complicated???

推荐答案

{
  "compilerOptions": {
    "typeRoots": [
      "./node_modules/@types",
      "./some-custom-lib"
    ]
  }
}

typeRoots字符串数组仅用于此目的.除了常规的"node_modules/@ type"之外,还添加一个自定义的打字文件夹.

the typeRoots string array is just for that. In addition to your regular "node_modules/@type", add a custom made typings folder.

这篇关于TypeScript:指定目录以查找模块类型定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆