2

I'm just starting with front-end web developpement(javascript hell with all these package manager/bundler) and I'm trying to use typescript + browsify

so I create a index.ts file and download the uniq module(using npm) just to test ts file compilation

here is my 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;
}

directory structure

.
├── entry.ts
├── node_modules
│   └── uniq
│       ├── LICENSE
│       ├── package.json
│       ├── README.md
│       ├── test
│       │   └── test.js
│       ├── uniq.d.ts
│       └── uniq.ts
└── package.json

but when I try to compile the index.ts I got this error :

error TS2688: Cannot find type definition file for 'uniq'.
2
  • Did you install the typings definition for it? You currently have your reference pointing to the definition file in the typings folder, but I don't see that in your directory structure. Commented Sep 26, 2016 at 19:00
  • @DaveV repair the mistake, i was just verifying that the d.ts file need not to be in the same folder as the .js file, still not working Commented Sep 26, 2016 at 19:05

1 Answer 1

3

First

you probably have the path wrong:

/// <reference path="node_modules/uniq/uniq.d.ts" />

Maybe ../../node_modules/uniq/uniq.d.ts. Instead of britle paths like this please use tsconfig.json : https://basarat.gitbooks.io/typescript/content/docs/project/tsconfig.html

Second

Based on the .d.ts you showed your import import {unique} from "uniq"; is also wrong. It should be import unique = require('uniq') since its a single function export. You will get an error about this anyways after you fix first. Enjoy 🌹

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.