# "IndexSignature not supported" error and Object.keys() not working

**URL:** https://forum.makecode.com/t/indexsignature-not-supported-error-and-object-keys-not-working/28994
**Category:** Help
**Created:** [May 29, 2024, 2:51am UTC](https://forum.makecode.com/t/indexsignature-not-supported-error-and-object-keys-not-working/28994 "2024-05-29T02:51:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ARandomGuyOnMakeCode](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/arandomguyonmakecode/32/22983_2.png) [@ARandomGuyOnMakeCode](https://forum.makecode.com/u/ARandomGuyOnMakeCode)
#### Post date: [May 29, 2024, 2:51am UTC](https://forum.makecode.com/t/indexsignature-not-supported-error-and-object-keys-not-working/28994/1 "2024-05-29T02:51:25Z")

</div>

So, I’m trying to index an object with a string. It’s not going very well. At first when I tried to do this, I got an error that stated that the object’s class didn’t have an index signature, so I added one. This worked just fine, until it just stopped working for no apparent reason. After a while, the index signature that I added gave the error, “IndexSignature not supported.” This didn’t happen before, so I have no clue why it’s happening. The weird thing is that I can use strings to index the object, meaning it works just fine, but when I do I get an error that says, “Dereferencing null/undefined value.” Also, for some reason when I try to print or use the keys of an object that was a child of a class by using the `Object.keys()` function, it doesn’t work, but when I try with a normal object, it works just fine. The weird thing is that then I print the type of the array, it returns what you would expect (it returns `"object"`).

Here are some examples of what I am talking about:  
“IndexSignature not supported” Error:

```auto
interface ExampleInterface {
    [key: string]: any
}

//% blockNamespace=tweenExtension
class ExampleClass implements ExampleInterface {
    [key: string]: any // Error: "IndexSignature not supported"
    exampleProperty1?: Vector2
    exampleProperty2?: Vector2
    exampleProperty3?: Vector2
    exampleProperty4?: Vector2
    exampleProperty5?: Vector2

    arrayOfExampleProperties: { examplePropertyIndex: number, value: Vector2 }[] = []
}

```

Object.keys() function issue:

```auto
class ExampleClass {
    x: number
    y: number

    constructor(_x: number, _y: number) {
        this.x = _x
        this.y = _y
    }
}
console.log(Object.keys(new ExampleClass(5,5))) // Expectation: Returns "[x,y]", Reality: Returns nothing. Absolutely nothing.
let example = new ExampleClass(3,4)
console.log(Object.keys(example)) // Expectation: Returns "[x,y]", Reality: Returns nothing.
let exampleArray = Object.keys(example)
console.log(exampleArray[0]) // Expectation: Returns "x", Reality: Returns nothing.
console.log(exampleArray[0] + "tale") // Expectation: Returns "xtale", Reality: Returns "undefinedtale"

let exampleObject = {x: 5, y: 5}
console.log(Object.keys(exampleObject)) // Expectation: Returns "[x,y]", Reality: Returns "[x,y]"
let exampleArray2 = Object.keys(exampleObject)
console.log(exampleArray2[0]) // Expectation: Returns "x", Reality: Returns "x"
console.log(exampleArray2[0] + "tale") // Expectation: Returns "xtale", Reality: Returns "xtale"

```

Any and all help is greatly appreciated. Thanks in advance.

---

<div class="post-metadata">

### Author: ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)
#### Post date: [May 29, 2024, 9:32pm UTC](https://forum.makecode.com/t/indexsignature-not-supported-error-and-object-keys-not-working/28994/2 "2024-05-29T21:32:51Z")

</div>

Unfortunately, makecode uses _static typescript_, which [does not support](https://makecode.com/language) the behaviour you’re trying to accomplish.

> `Object.keys(x)` is not yet supported when `x` is dynamically a class type. It is supported when `x` was created with an object literal (eg., `{}` or `{ a: 1, b: "foo" }`). The order in which properties are returned is order of insertion with no special regard for keys that looks like integer (JavaScript has [really counter-intuitive behavior](https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/) here). When we support `Object.keys()` on class types, the order will be the static order of field definition.

I asked something like this a while back, same outcome

> [@How do I get names from objects instantiated from a class?](https://forum.makecode.com/t/how-do-i-get-names-from-objects-instantiated-from-a-class/24283):
>
> Basicaly, writing up an object with properties and fetching its keys with Object.keys() works fine. let foo = { bar: "abc", baz: () =\> {} } // Logs "bar", "baz" console.log(Object.keys(foo)); However, getting keys from a class instance just yields an empty array class Foo { bar: number; baz() { // code goes here } } // Expecting "bar", "baz" // Output is empty console.log(Object.keys(new Foo())); Why is this the case? Is there a way to achieve what I’m trying to…

---

<div class="post-metadata">

### Author: ![ARandomGuyOnMakeCode](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/arandomguyonmakecode/32/22983_2.png) [@ARandomGuyOnMakeCode](https://forum.makecode.com/u/ARandomGuyOnMakeCode)
#### Post date: [May 30, 2024, 5:04pm UTC](https://forum.makecode.com/t/indexsignature-not-supported-error-and-object-keys-not-working/28994/3 "2024-05-30T17:04:25Z")

</div>

Yeah, I figured that was the case. Thanks for your help! 🙂 👍
