# Functions returning generic arrays break type inferences

**URL:** <https://forum.makecode.com/t/functions-returning-generic-arrays-break-type-inferences/4734>\
**Category:** Arcade\
**Created:** [December 2, 2020, 1:13am UTC](https://forum.makecode.com/t/functions-returning-generic-arrays-break-type-inferences/4734 "2020-12-02T01:13:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tncbbthositg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/tncbbthositg/32/2288_2.png) [@tncbbthositg](https://forum.makecode.com/u/tncbbthositg)\
**Post date:** [December 2, 2020, 1:13am UTC](https://forum.makecode.com/t/functions-returning-generic-arrays-break-type-inferences/4734/1 "2020-12-02T01:13:20Z")

</div>

Hey guys,

```
 I ran into an issue with some typescript generics. Everything worked fine in typescript, but the block editor wasn't happy.

 Here's my minimal reproducible example: https://makecode.com/_euc82gFy4f3q

 Basically, if I have a generic function like tihs:

```

```auto
    /**
     * TODO: make an array of things
     * @param thing what to make an array of
     */
    //% block
    export function arrayify<T>(thing: T): T[] {
        return [thing];
    }

```

I can use it to create a variable just fine. But, when I try to use that variable outside the scope of declaration, it infers the type to be `T` and I get a type error saying it cannot find type `T`.

```auto
function doSomething () {
    return aThing
}
let aThing: T[] = []
aThing = custom.arrayify(0)

```

Where do you usually submit issues like this? Has anybody found a good way around this?

Thanks!!

---

<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:** [December 2, 2020, 1:28am UTC](https://forum.makecode.com/t/functions-returning-generic-arrays-break-type-inferences/4734/2 "2020-12-02T01:28:17Z")

</div>

Most issues go here:

> **[microsoft/pxt-arcade](https://github.com/microsoft/pxt-arcade/issues)**
>
> Arcade game editor based on Microsoft MakeCode. Contribute to microsoft/pxt-arcade development by creating an account on GitHub.

  
But since your problem is related to the block editor, it might actually go somewhere else…

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [December 2, 2020, 3:03am UTC](https://forum.makecode.com/t/functions-returning-generic-arrays-break-type-inferences/4734/3 "2020-12-02T03:03:32Z")

</div>

Generics aren’t supported in blocks currently - the existing array methods that are generic are heavily special cased our blocks compiler / fairly fragile. You can possibly get away with using `any` / `any[]` for the types to get something kind of working (but of course it won’t identify the types correctly / that is also a bit fragile as it stands)

---

<div class="post-metadata">

**Author:** ![tncbbthositg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/tncbbthositg/32/2288_2.png) [@tncbbthositg](https://forum.makecode.com/u/tncbbthositg)\
**Post date:** [December 2, 2020, 5:09pm UTC](https://forum.makecode.com/t/functions-returning-generic-arrays-break-type-inferences/4734/4 "2020-12-02T17:09:19Z")

</div>

Thanks. I was able to get it to work with `any`. What I was hoping to make was a jagged array of colors for a neopixel ring. Jagged arrays didn’t work out of the gate so I was going to make a function with a `switch` to effectively mimic a jagged array.

I wanted to have a helper block for making it easier to make an array of 24 colors when you only needed 2 colors to repeat 24 times. I figured I’d make them generic so they could be reused. I could also just explicitly make them `number[]`s and it would probably work.

I ended up just making a class to act like the jagged array and that got around the generics issue because there wasn’t a need for a global reference to each color array.

What I’m struggling with is what do I build to help my kids solve the problems they want to solve vs. what do I tell them isn’t possible so that they’ll work around it? 🙂

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [December 3, 2020, 4:49pm UTC](https://forum.makecode.com/t/functions-returning-generic-arrays-break-type-inferences/4734/5 "2020-12-03T16:49:42Z")

</div>

> **[JavaScript](https://arcade.makecode.com/javascript)**
>
> The Microsoft MakeCode programming environment uses JavaScript along with the Static TypeScript language.

Maybe this answers some of your questions with what is possible, as the Javascript is Static Typescript:

> **[MakeCode Languages: Blocks, Static TypeScript and Static Python](https://makecode.com/language)**
>
> MakeCode programs can be authored in Blocks, Static TypeScript or Static Python.
