This project is read-only.

type definitions for Q and TypeScript 0.9.5 beta

Topics: Language Specification
Nov 18, 2013 at 9:44 PM

It would appear the type definitions from NuGet for Kris Kowalski's Q promises library no longer works in TS 0.9.5 beta. It recognises the two declare function Q<T> overloads but it does not recognise any of the definitions that follow in the declare module Q below. So I get loads of errors saying that property defer or property resolve do not exist on value of type 'typeof Q'. Any advise on how the q.d.ts file must be updated for 0.9.5?

many thanks

Nov 18, 2013 at 10:07 PM
When did you last pull the definition file? I just grabbed the latest version from and I'm not seeing any problems with it.

Can you provide a sample that shows the error you are experiencing? Also, if you can log this over in the "Issues" rather than the "Discussions" section, we'll be able to track it easier.

Nov 18, 2013 at 10:11 PM
The latest definitions I see from DefinitelyTyped don't have any errors in 0.9.5 for me. Can you link to exactly which one you're using?
Nov 19, 2013 at 10:26 AM
The issue was not with the q.d.ts file itself not compiling, but none of my code that referenced Q compiled. It appears by reintroducing
/// <reference path="..\lib\q.d.ts"/>
at the top of each file solved the issue. I thought these references were no longer required. Perhaps its because my project is a SharePoint 2010 project. Is that something I should log over in 'Issues'?
Nov 19, 2013 at 10:33 AM
Hmm, spoke too soon perhaps. Every now and then the errors with Q reappear again, even with the reference paths, only to disappear again after a rebuild. I'll log an issue.
Nov 25, 2013 at 10:52 PM
Edited Nov 25, 2013 at 10:59 PM
As the guy who wrote the Q.d.ts definition and have spent two hours fighting these errors today, I can agree that there is some sort of bug but I think it's a typescript compiler error.

The errors are occurring not in the q.d.ts file but rather in any file that uses it. The errors state that Q's functions, ie. Q.fcall don't exist as properties on the Q object.

I defined the Q object in two different ways, first as two functions:
declare function Q<T>(value: T): Q.Promise<T>;
declare function Q<T>(promise: Q.IPromise<T>): Q.Promise<T>;

Then Q is declared as a module with interfaces and functions. (If there is a better way to declare such things on a function in a d.ts file, I'm unaware) I think the compiler is only considering the function declarations and ignoring the module declaration.

My quickie fix is to move those two function declarations to after the module declaration. I know that position should not matter but it makes a difference in this case. I found that I also have to, at least temporarily, comment out the second function declaration as the TS compiler complains it is a duplicate. Very strange. As long as the second declaration is not used by your code, it will get you through.

In any event, I hope this helps someone.
Nov 26, 2013 at 2:08 AM
The issue tracking this is here
Nov 28, 2013 at 9:15 PM
I've created a pull request to definatelytyped that eliminates the error. It's not accepted yet but should be within the next day or two. I had to refactor the declarations quite a bit, but it will work without any changes to code that uses it.
Dec 2, 2013 at 4:16 PM
I'm in a bit of a quandary now as my pull request has been rejected because it failed the tests on the definatelytyped build. I believe it's failing because they're not using the 0.9.5 build. Until that build is released, I don't think it will be accepted. When I manually ran that test, I get some other weird errors that looks like there are further problems with 0.9.5. So, I'm kindof in no man's land right now. It is very possible that the original code will work once the workitem posted above is addressed, making the changes unnecessary. Guess we'll see.