Created
October 30, 2016 22:49
-
-
Save Alex2357/854cac7abf1bd89ad02232aea00fa575 to your computer and use it in GitHub Desktop.
C:\Users\Alex\WebstormProjects\Tutorial01\Tests>tsc TS2.0.6Bug.ts --target ES6
TS2.0.6Bug.ts(28,21): error TS2322: Type 'void | IFoo[]' is not assignable to ty
pe 'IFoo[]'. Type 'void' is not assignable to type 'IFoo[]'.
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
interface IFoo{ | |
square:number | |
} | |
( | |
async () => { | |
async function squareFun(i:number) : Promise<IFoo>{ | |
if (i === 2) | |
throw 'squareFun1 throw 2'; | |
return Promise.resolve({square: i * i}); | |
} | |
async function getSquares3(): Promise<IFoo[]>{ | |
//I like this as I don't need to use Promise.all<IFoo> | |
var squares = await Promise.all([squareFun(1), squareFun(4)]); | |
return squares; | |
} | |
async function getSquares(): Promise<IFoo[]>{ | |
try { | |
var promises = [1, 2, 3].map(n => squareFun(n)); | |
var squares = Promise.all(promises); | |
//It can be compiled | |
//var cs : Promise<IFoo[]> = squares.catch(err => console.log('Catched error Promise.catch:' + err)); | |
//This cannot be compiled | |
var cs = squares.catch(err => console.log('Catched error Promise.catch:' + err)); | |
var t : IFoo[] = await cs; | |
return t; | |
} | |
catch(err){ | |
console.log('Catched error try/catch:' + err); | |
} | |
} | |
var squares = await getSquares(); | |
if (squares) | |
squares.forEach(s => console.log('square:' + s.square)); | |
} | |
)(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment