Skip to content
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

Unexpected behaviour when overriding setters without overriding getters. #14842

Closed
KidScripty opened this issue Mar 24, 2017 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@KidScripty
Copy link

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)

Code

class ClassA{
	protected _id:number = 1;
	public get id():number{
		return this._id;
	}
	public set id(value:number){
		this.id = value;
	}
}

class ClassB extends ClassA{
	public get id():number{
		return this._id;
	}
	public set id(value:number){
		this.id = value;
	}
}

class ClassC extends ClassB{
	public set id(value:number){
		this.id = value;
	}
}

class ClassD extends ClassB{

}


let myClassA = new ClassA();
let myClassB = new ClassB();
let myClassC = new ClassC();
let myClassD = new ClassD();

Expected behavior:

console.log("myClassA : ", myClassA.id); //1
console.log("myClassB : ", myClassB.id); //1
console.log("myClassC : ", myClassC.id); //1
console.log("myClassD : ", myClassD.id); //1

Actual behavior:

console.log("myClassA : ", myClassA.id); //1
console.log("myClassB : ", myClassB.id); //1
console.log("myClassC : ", myClassC.id); //UNDEFINED
console.log("myClassD : ", myClassD.id); //1
@RyanCavanaugh RyanCavanaugh added Working as Intended The behavior described is the intended behavior; this is not a bug Duplicate An existing issue was already created and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Mar 24, 2017
@RyanCavanaugh
Copy link
Member

This is the ES6-specified behavior. See #13669, #13432, #11596

@KidScripty
Copy link
Author

Alright thank you for clarification.

@microsoft microsoft locked and limited conversation to collaborators Jun 21, 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

2 participants