【发布时间】:2016-06-18 16:56:09
【问题描述】:
给定以下目录结构:
{project}/
|-- node_modules/
| |-- lodash
|-- src/
| |-- index.ts
|-- lib/ (output)
| |-- index.js
| |-- index.d.ts
|-- package.json
|-- tsconfig.json
虽然内置的输出功能正常; tsc 命令抱怨当我使用以下任何一种时它无法解析 lodash 模块:
import _ from "lodash";
import _ = require("lodash");
import * as _ from "lodash";
在我的“tsconfig.json”文件中,我包含了以下内容:
...
"target": "es6",
"sourceMap": true,
"module": "commonjs",
"moduleResolution": "node",
...
但尽管如此,它仍然没有找到任何使用 npm 安装的模块。
我是否遗漏了让 TypeScript 找到这些模块所需的东西?
我意识到没有 TypeScript 定义文件 TypeScript 无法提供额外的类型检查;但是,这些肯定应该默认为 any 类型吧?
【问题讨论】:
-
确保您拥有 Typescript 1.6 或更高版本。这是一个good discussion,说明它在 1.6 之前的“工作方式”以及之后的工作方式。
标签: typescript npm tsconfig