# Typehinting a list of integers

**URL:** https://forum.makecode.com/t/typehinting-a-list-of-integers/7080
**Category:** micro:bit
**Created:** [March 29, 2021, 2:38pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080 "2021-03-29T14:38:01Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![dog](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dog](https://forum.makecode.com/u/dog)
#### Post date: [March 29, 2021, 2:38pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/1 "2021-03-29T14:38:01Z")

</div>

I have recently discovered that the microbit makecode editor requires to know the type of list before runtime. I have been using typehints to achieve this like so:  
enemies: List[game.LedSprite] = []  
however when trying to make a list of integers I could not get it to work  
I have tried all of these:  
purge: List[int] = []  
purge: List[Number] = []  
purge: List[Integer] = []

yet none of these work!  
In order to make this work I need to use a really jank solution:  
purge = [0]  
purge.remove\_at(0)  
Surely there must be a way to do this with typehints, if you know please let me know.

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [March 29, 2021, 3:37pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/2 "2021-03-29T15:37:12Z")

</div>

It’s `number`, not `Number`. That always bites me in the behind 😅

---

<div class="post-metadata">

### Author: ![dog](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dog](https://forum.makecode.com/u/dog)
#### Post date: [March 30, 2021, 3:22pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/3 "2021-03-30T15:22:05Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/44df344727aa460ee5a2b79d54c7c3aee3f350a8.png)

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [March 30, 2021, 4:19pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/4 "2021-03-30T16:19:16Z")

</div>

What about this:

```typescript
let test: number[] = [];

```

You can also do this, but then it starts to look like C++: 🤔

```typescript
let test: Array<number> = [];

```

---

<div class="post-metadata">

### Author: ![dog](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dog](https://forum.makecode.com/u/dog)
#### Post date: [March 30, 2021, 9:05pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/5 "2021-03-30T21:05:59Z")

</div>

I’m using python and that doesn’t work.  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/e469cb3da44b78eadd9c2e79244309f636caf352.png)

---

<div class="post-metadata">

### Author: ![dog](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dog](https://forum.makecode.com/u/dog)
#### Post date: [March 30, 2021, 9:06pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/6 "2021-03-30T21:06:27Z")

</div>

> [@UnsignedArduino](#):
>
> `let test: Array<number> = [];`

Okay so strangely in a new project this works:  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/d/dc0c03d688ca895a8e049d9db90875f5c2e3df82.png)  
However when I try and use the exact same code in my project where I need this I get this three errors, “Unused label”, “‘number’ only refers to a type, but is being used as a value here” and “Expression expected.”  
And now I think I found the problem, for some reason when you put it in a loop or maybe its just when you indent it these errors appear, but when not indented it works fine, very confusing.

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [March 30, 2021, 10:33pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/7 "2021-03-30T22:33:17Z")

</div>

👀 You are using Python???

Sorry for all the confusion, what I said is for TypeScript. For Python, it’s:

```auto
purge: list[int] = []

```

And `float` if you are using decimals.

---

<div class="post-metadata">

### Author: ![dog](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dog](https://forum.makecode.com/u/dog)
#### Post date: [March 31, 2021, 3:10am UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/8 "2021-03-31T03:10:02Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/e/e2f18d947d59f2a4e9547f1964dc8bef267aebeb.png)  
This doesn’t work either…  
and I already tried using List[int] as said in the initial post.

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [March 31, 2021, 3:48pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/9 "2021-03-31T15:48:17Z")

</div>

> [@dog](#):
>
> …and I already tried using List[int] as said in the initial post.

`List` and `list` are 2 different things! 😉  
I’ve ran out of ideas - Python is still in beta so I would report a bug issue [here](https://github.com/microsoft/pxt-arcade/issues).

---

<div class="post-metadata">

### Author: ![dog](https://avatars.discourse-cdn.com/v4/letter/d/13edae/32.png) [@dog](https://forum.makecode.com/u/dog)
#### Post date: [March 31, 2021, 9:00pm UTC](https://forum.makecode.com/t/typehinting-a-list-of-integers/7080/10 "2021-03-31T21:00:33Z")

</div>

> [@UnsignedArduino](#):
>
> `List` and `list` are 2 different things! 😉

Yeah I know, **list** is the builtin python type but **List** is for typehinting.

> [@UnsignedArduino](#):
>
> I’ve ran out of ideas - Python is still in beta so I would report a bug issue [here](https://github.com/microsoft/pxt-arcade/issues).

Okay thank you!
