-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: 2.7.0-dev.20171031
Code
declare function f(a: string, c: string): void;
function f2(a?: string, b?: string[]): void {
if (a && b) {
b.forEach( //b: string[]
c => f(a, c) //a: string (OK)
);
}
}
function f3(a: string|undefined, b: string[]|undefined): void {
if (a && b) {
b.forEach( //b: string[]
c => f(a, c) //a: string (OK)
);
}
}
function f4(x: any): void {
let a: string|undefined = x.getA();
let b: string[]|undefined = x.getB();
if (a && b) {
b.forEach( //b: string[]
c => f(a, c) //a: string|undefined (should be just string)
);
}
}
function f5(x: any): void {
let a: string|undefined = x.getA();
let b: string[]|undefined = x.getB();
if (a && b) {
f(a, b[0]) //a: string (OK)
}
}
function f6(x: any): void {
let a: string|undefined = x.getA();
let b: string[]|undefined = x.getB();
if (a) {
let d: 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'.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created