Reputation: 1368
I want to return the last promise in a chain as the result of a function. I'm using TypeScript 1.7 and native, ES6 promises.
I tried this, but TS considers the first promise as the return value (the Uint8Array), not the CryptoKey from importKey. I've seen JavaScript examples that make me think the last promise is actually the return value, so maybe TS is just confused?
private getKey(): Promise<Uint8Array> {
return localforage.getItem<Uint8Array>("key")
.then<Uint8Array>((derivedKeyData) => {
return crypto.subtle.importKey("raw", derivedKeyData, { name: "AES-GCM" }, false, ["decrypt"]);
});
}
How do I return the inner promise as the result of the function? Or at least convince TS that's what's really happening without making the function's return type "any"?
Upvotes: 2
Views: 548
Reputation: 21005
I had a look at your code on http://www.typescriptlang.org/Playground and the issue seems to be that the inbuilt resulting type of importKey is 'any'
Upvotes: 1