# Type annotation cannot appear on a constructor declaration

**URL:** https://forum.makecode.com/t/type-annotation-cannot-appear-on-a-constructor-declaration/4035
**Category:** micro:bit
**Created:** [October 23, 2020, 7:00am UTC](https://forum.makecode.com/t/type-annotation-cannot-appear-on-a-constructor-declaration/4035 "2020-10-23T07:00:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![linus\_janns](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@linus\_janns](https://forum.makecode.com/u/linus_janns)
#### Post date: [October 23, 2020, 7:00am UTC](https://forum.makecode.com/t/type-annotation-cannot-appear-on-a-constructor-declaration/4035/1 "2020-10-23T07:00:09Z")

</div>

Im trying out some stuff for a project and I have found it that I would prefer to use classes for the thing im doing. The problem occurs when having a constructor. It then returns me with a error “Line 3: Type annotation cannot appear on a constructor declaration.”.

Here is the test code: [https://pastebin.com/jxFhZ01Y](https://pastebin.com/jxFhZ01Y)

I also tried to do it according to the microbit python docs. But that returns me with “Line 4: the field ‘string’ of ‘Testclass’ is static; Line 7: the field ‘string’ of ‘Testclass’ is static”

Here is the code for that: [https://pastebin.com/RatUxV7f](https://pastebin.com/RatUxV7f)

---

<div class="post-metadata">

### Author: ![poocontrol](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@poocontrol](https://forum.makecode.com/u/poocontrol)
#### Post date: [August 23, 2021, 6:11pm UTC](https://forum.makecode.com/t/type-annotation-cannot-appear-on-a-constructor-declaration/4035/2 "2021-08-23T18:11:39Z")

</div>

I run into the same problem too, any advise here?

---

<div class="post-metadata">

### Author: ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)
#### Post date: [August 24, 2021, 5:49pm UTC](https://forum.makecode.com/t/type-annotation-cannot-appear-on-a-constructor-declaration/4035/3 "2021-08-24T17:49:52Z")

</div>

This isn’t a solution, but it seems like this is related to Python parsing of constructors. MakeCode translates Python:

```auto
class Testclass:
    def __init__ (self, text):
        self.string = text

```

into TypeScript like:

```auto
class Testclass {
    string: string
    constructor(text: string): Testclass {
        this.string = text
    } 
}

```

Note the `Testclass` annotation on the `constructor` (an error). It can be removed from the JavaScript, but then the resulting code can’t be translated back to Python.

Even [examples given in pxt](https://github.com/microsoft/pxt/blob/d0ec5d92f120492142330e264cff57ba5d5cb364/common-docs/python/classes.md#classes) seem to fail. It may help to raise an issue via [https://github.com/microsoft/pxt/](https://github.com/microsoft/pxt/).

Bill
