-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
The following code demonstrates a bug between interface fields and the class properties that the TypeScript compiler accepts in their place. The IDisplayInfo interface below has a DisplayName field. The test1 class implements this interface via a setter property function. The test2 class implements this interface via a getter property function. An instance of each is instantiated and each instance gets and sets the DisplayName property. This code successfully compiles, though it will obviously error at run-time.
module myModule{
export interface IDisplayInfo{
DisplayName: string;
}
class test1 implements IDisplayInfo
{
private _displayName: string;
set DisplayName(name: string) {
this._displayName = name;
}
}
class test2 implements IDisplayInfo{
private _displayName: string;
get DisplayName() {
return this._displayName;
}
}
var t1: test1 = new test1();
var t2: test2 = new test2();
t1.DisplayName = "hi";
var dn = t1.DisplayName;
t2.DisplayName = "goodbye";
dn = t2.DisplayName;
}
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code