Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package installed from npm still has Q in d.ts file #63

Closed
DSakura207 opened this issue Nov 25, 2016 · 4 comments
Closed

Package installed from npm still has Q in d.ts file #63

DSakura207 opened this issue Nov 25, 2016 · 4 comments

Comments

@DSakura207
Copy link

Hi,
I am now writing an tfs web application. When I compile my application, tsc complains:
node_modules/vso-node-api/FileContainerApi.d.ts(1,20): error TS2307: Cannot find module 'q'. node_modules/vso-node-api/VsoClient.d.ts(1,20): error TS2307: Cannot find module 'q'.

In FileContainerApi.d.ts:

import Q = require('q');
import VsoBaseInterfaces = require('./interfaces/common/VsoBaseInterfaces');
import FileContainerApiBase = require("./FileContainerApiBase");
...

If I remove the import and replace Q.Promise with Promise, compilation is good.

Here are my question:
Is it safe for me to remove them?
Do I need any special setting for tsconfig? Current I have "target": "es6".

Thanks!

@bgavrilMS
Copy link
Member

I think you're missing the typings for Q.

@bgavrilMS
Copy link
Member

Here's a project that we wrote that uses vsts-node-api https://github.com/Microsoft/tfsgit-pr-injector/blob/master/typings.json

@DSakura207
Copy link
Author

Thanks! It works perfectly. Can you please give me some hints for the reason? I am new to NodeJS and TypeScript.

@bgavrilMS
Copy link
Member

Sure. Typescript is a superset of javascript, and many libraries are still in pure javascript. So typescript came up with the concept of typings - a way to wrap existing js libraries in a typescript interface. Have a look at q.d.ts from the typings directory for an example - it's quite human readable. You'll note that you don't need typings for vsts-node-api, because it's already written in typescript.

So now there are a few repositories of "typings", communities making sure old javascript libs can easily be used in typescript projects. Check out https://github.com/typings/typings for how to easily pull them in your nodejs + typescript proj.

To get back to your error - although you had installed the q module, typescript could not use Q.Promise because it's missing a typings file that links the ts interface for the underlying js logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants