# Problems with inherited getters and setters

**URL:** <https://forum.makecode.com/t/problems-with-inherited-getters-and-setters/30245>\
**Category:** Help\
**Created:** [August 22, 2024, 5:06am UTC](https://forum.makecode.com/t/problems-with-inherited-getters-and-setters/30245 "2024-08-22T05:06:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chembot](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/chembot/32/14245_2.png) [@chembot](https://forum.makecode.com/u/chembot)\
**Post date:** [August 22, 2024, 5:06am UTC](https://forum.makecode.com/t/problems-with-inherited-getters-and-setters/30245/1 "2024-08-22T05:06:05Z")

</div>

I have an abstract class with a protected variable, and a getter and setter for it. I know that arcade doesn’t allow abstract functions, so I gave them default implementations.

```auto
abstract class Foo {
    protected _x: number;
    public get x(): number {
        return this._x;
    }
    public set x(nx: number) {
        this._x = nx;
    }
    constructor() {
        this._x = 0;
    }
}

```

I have a subclass that I want to treat the member as readonly, like this:

```auto
class Bar extends Foo {
    // getter required to match setter, but left unaltered.
    public get x(): number {
        return this._x;
    }
    // no setting allowed, functionally making _x readonly
    public set x(nx: number) {
        throw "nuh uh";
    }
    constructor(x: number) {
        super()
        this._x = x
    }
}

```

Tested using this:

```auto
let testBar = new Bar(5);
game.splash("bar x: ", "" + testBar.x);

```

It threw the error in the constructor, despite both the base constructor and the overridden one not using the setter. When I replaced the `throw` with a `game.splash("no")`, the test output was “bar x: undefined”. Also interestingly, when I followed up the test code with `testBar.x = 3` the slash “no” appeared two more times. Also tried making the class not abstract, but that had no effect. Tried doing `let testBar: Foo = new Bar(5)`, but that had no effect.

Not sure what exactly is doing on under the hood, or how to fix it. I need the variable to be settable in the superclass but not in the subclass. I tried making it public in the superclass and private in the subclass, but that leads to “redefinition of \_x as a field”. I know that the `override` keyword isn’t usable, and I can’t make the getter and setter abstract. The `Omit`, `Exclude` and `Pick` keywords don’t seem to work either.

Please let me know if I’m approaching this in the wrong way. Thanks!

---

<div class="post-metadata">

**Author:** ![chembot](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/chembot/32/14245_2.png) [@chembot](https://forum.makecode.com/u/chembot)\
**Post date:** [October 11, 2024, 9:21pm UTC](https://forum.makecode.com/t/problems-with-inherited-getters-and-setters/30245/2 "2024-10-11T21:21:12Z")

</div>

I’m not sure what has changed but the issue seems to be fixed. The test code correctly throws the error, and changing it to a splash screen works as well. I’m not sure about `Omit`, `Exclude`, and `Pick` but the code works fine. Maybe it was an update to makecode?
