Skip to content

False positive 'This condition will always return false' comparing this with an instance of a subclass #46709

@yujiang

Description

@yujiang

Bug Report

💻 Code

class AA {
	do1 (){
		const b = dd.getB();
		if (this === b){
			console.log("this === b");
		}
	}
}

class BB extends AA{
	getB():BB {return this;}
}

let dd = new BB();
dd.do1();

🙁 Actual behavior

at line: if (this === b){
error TS2367: This condition will always return 'false' since the types 'this' and 'BB' have no overlap.

and execute the compiled js file will output:
this === b

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions