TypeScript Version: 2.7.0-dev.20171031
Code
declarefunctionf(a: string,c: string): void;functionf2(a?: string,b?: string[]): void{if(a&&b){b.forEach(//b: string[]c=>f(a,c)//a: string (OK));}}functionf3(a: string|undefined,b: string[]|undefined): void{if(a&&b){b.forEach(//b: string[]c=>f(a,c)//a: string (OK));}}functionf4(x: any): void{leta: string|undefined=x.getA();letb: string[]|undefined=x.getB();if(a&&b){b.forEach(//b: string[]c=>f(a,c)//a: string|undefined (should be just string));}}functionf5(x: any): void{leta: string|undefined=x.getA();letb: string[]|undefined=x.getB();if(a&&b){f(a,b[0])//a: string (OK)}}functionf6(x: any): void{leta: string|undefined=x.getA();letb: string[]|undefined=x.getB();if(a){letd: string=a.toLowerCase();//a: string (OK)if(b){b.forEach(//b: string[]c=>f(a,c)//a: string|undefined (should be just string));}}}Expected behavior:
No error, a: string|undefined should be string inside a if (a && b)
Actual behavior:
error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
TypeScript Version: 2.7.0-dev.20171031
Code
Expected behavior:
No error,
a: string|undefinedshould bestringinside aif (a && b)Actual behavior:
error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.