【发布时间】:2016-09-26 18:42:52
【问题描述】:
我刚开始使用前端 Web 开发(所有这些包管理器/捆绑器的 JavaScript 地狱),我正在尝试使用 typescript + browsify
所以我创建一个 index.ts 文件并下载 uniq 模块(使用 npm)只是为了测试 ts 文件编译
这是我的 index.ts
/// <reference path="node_modules/uniq/uniq.d.ts" />
import {unique} from "uniq";
var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];
console.log(unique(data));
uniq.d.ts
// Type definitions for uniq
// Project: https://www.npmjs.com/package/uniq
// Definitions by: Hans Windhoff <https://github.com/hansrwindhoff>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Uniq{
<T>(ip:Array<T>): Array<T>;
}
declare var uniq :Uniq;
declare module "uniq" {
export = uniq;
}
目录结构
.
├── entry.ts
├── node_modules
│ └── uniq
│ ├── LICENSE
│ ├── package.json
│ ├── README.md
│ ├── test
│ │ └── test.js
│ ├── uniq.d.ts
│ └── uniq.ts
└── package.json
但是当我尝试编译 index.ts 时,我得到了这个错误:
error TS2688: Cannot find type definition file for 'uniq'.
【问题讨论】:
-
您是否为它安装了
typings定义?您当前的参考指向了类型文件夹中的定义文件,但我在您的目录结构中没有看到。 -
@DaveV 修复错误,我只是在验证 d.ts 文件不需要与 .js 文件位于同一文件夹中,仍然无法正常工作
标签: javascript node.js typescript browserify