Hi.
I'm using your Q definition file, and I'm getting the error Cannot convert 'Q.Promise<any>' to 'Q.Promise<string>' when running the following code. I can see why TypeScript would have an issue inferring the type in this situation, but I'm not sure how I can get around this?
function SomeFunction() : Q.Promise<string> {
var deferred = Q.defer();
// Some async function
setTimeout(function() {
deferred.resolve('SomeString');
});
return deferred.promise;
}
Use this:
var deferred = Q.defer<string>();
Thank you!! Worked a charm!
There's a similar issue in cases like this.
class SomeType {}
function SomeFunction() : Q.Promise<string[]> {
return Q<string[]>(['']);
}
function SomeOtherFunction() : Q.Promise<SomeType> {
return SomeFunction().then<SomeType>(function() {
return new SomeType();
});
}
in which case I'm getting the error Cannot convert 'Q.Promise<SomeType>' into 'Q.Promise<SomeType>'
That's strange. Are you sure you get exactly this error message?
Yeh that's the exact error. Can you not reproduce?
It isn't reproduced: Link to playground (it will take some time to load).
it even works with following code:
class SomeType {}
function SomeFunction() : Q.Promise<string[]> {
return Q(['']);
}
function SomeOtherFunction() : Q.Promise<SomeType> {
return SomeFunction().then(function() {
return new SomeType();
});
}
without explicit types in generic arguments.
I think the issue may be within the Sublime Text typescript plugin as that is what is reporting the error, not the compiler.
Sent from my iPhone
On 24 Mar 2014, at 08:31, Igorbek [email protected] wrote:
it even works with following code:
class SomeType {}
function SomeFunction() : Q.Promise
return Q(['']);
}function SomeOtherFunction() : Q.Promise
{
return SomeFunction().then(function() {
return new SomeType();
});
}
without explicit types in generic arguments.—
Reply to this email directly or view it on GitHub.
Maybe. Try to compile source file with tsc and send error report if any exists.
Most helpful comment
Use this: