Last active
February 12, 2018 08:24
-
-
Save ThomasKruegl/db64a799b2c411c007f05276884e8197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function thisGetsCalled(): Promise<string> { | |
throw new Error("bla"); | |
} | |
function convert(error: any) { | |
throw new Error("different"); | |
} | |
async function main() { | |
// this is not working, error TS2322: Type 'string | void' is not assignable to type 'string'. | |
// Type 'void' is not assignable to type 'string'. | |
const result: string = await thisGetsCalled().catch(convert); | |
// this is working, but i would have to declare let result2 before the try, to work with it later | |
try { | |
const result2: string = await thisGetsCalled(); | |
} catch (error) { | |
convert(error); | |
} | |
// this is working (though i don't know why..) but i would prefer await style, there are more calls to follow. | |
thisGetsCalled() | |
.catch((error: any) => { throw new Error("different"); }) | |
.then((result3: string) => console.log(result3)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
solution: function convert(error: any): never { ... }