Skip to content

Bug? with "never" type #13325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bjornbacklund opened this issue Jan 6, 2017 · 1 comment
Closed

Bug? with "never" type #13325

bjornbacklund opened this issue Jan 6, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@bjornbacklund
Copy link

bjornbacklund commented Jan 6, 2017

TypeScript Version: 2.1.4.0

class C
{
	public f1() {
		return 1;
	}

	public f2()
	{
		if (this instanceof Sub)
			return 2;

		return this.f1(); // Does not compile: error "f1 does not exist on type never"
	}
}

class Sub extends C
{

}

Expected behavior:
Compile without error

Actual behavior:
Error "f1 does not exist on type never"

@akarzazi
Copy link

akarzazi commented Jan 6, 2017

instance of operator is out of order in TypeScript.
It uses shape comparison.

You can bypass it by adding a fake property:

class C
{
	public f1() {
		return 1;
	}

	public f2()
	{
		if (this instanceof Sub)
			return 2;

		return this.f1(); // ok
	}
}

class Sub extends C
{
    private _prop: string;
}

This issue is similar to : #11664

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 6, 2017
@mhegazy mhegazy closed this as completed Apr 19, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants