-
Notifications
You must be signed in to change notification settings - Fork 167
Open
Description
Below code section will never get executed. object x is of type string (Which is literal), and we are checking for instance String (Which is interface).
if(x instanceof String) {
x.substr(0)
}
See below sample code
function totalLength(x: string, y: string): number
function totalLength(x: any[], y: any[]): number
function totalLength(x: (string | any[]), y: (string | any[])): number {
var total: number = x.length + y.length;
if(x instanceof Array) {
x.push('TypeScript')
}
if(x instanceof String) {
x = x.substr(1,3);
}
console.log(x)
return total;
}
totalLength("first","second");
Expected output: eco
Actual output: first
Metadata
Metadata
Assignees
Labels
No labels