Error: Generic type 'Array<T>' requires 1 type argument(s)


I forgot about this one earlier…

When switching from JavaScript to blocks, MakeCode generates an error when trying to convert multidimensional arrays to blocks. The multidimensional arrays compile and run fine directly from JavaScript.

The error message is:
Generic type 'Array<T>' requires 1 type argument(s)

When switching back again to JavaScript the multidimensional array is changed to:

let tracks: Array[] = [[hihat], [drums], [b1]]

So it seems to infer and add a one-dimensional Array[] type to the variable, where a two- or multidimensional Array[][] type does not exist, and where the multidimensional array works fine in JavaScript without any added type specification to the variable.

Is this a bug in the conversion from JavaScript to blocks, or is it just not part of the feature set, where this should be solved in another recommended and equally performant way instead?

This can be replicated by opening the following code in the editor, then switching to blocks and then switching back to JavaScript, and finally observing e.g. line number 764:


  1. I am not sure if this recent topic about array trees is similar or related?
  2. I was expecting grey/black blocks with custom JavaScript code instead of this failed/not complete attempt at converting from JavaScript multidimensional arrays to array blocks.

Hm, I played around for a bit and got a min repro (slightly different end result, but I’m guessing it’s the same and it’s just specific details e.g. 2d arrays + slightly different usage that is resulting in a different badly generated type):

It looks like it’s a bad interaction between typing of variable in gray block & type inference in arrays (also perhaps some further edge cases with fixedInstance sneaking in, as music.Melody is one of those); I’d have to poke around, definitely a bug but it’s also very much an edge case – e.g. in this case there’s no real reason not to fix this to not have gray blocks in the first place by defining a little helper function in custom.ts

namespace myHelper {
    //% block
    export function whatIsThatMelody(a: string) {
        return new music.Melody(a);

and it should work fine again:

Here’s magic bossfight with a block swapped in for the direct new music.Melody()

(also will go ahead and tag @richard in case he has different opinions on how important this is to prioritize a fix for~)

1 Like

Wow, that was quick and thorough, @jwunderl!!

Interesting, I thought it had something to do with the basic multidimensional array handling, and not type inference from the specific music.Melody, since it inferred Array<T>[].

But I see the same now in your one dimensional example, where it infers number[], and it works if manually set/hinted to any[] or music.Melody[]. So I guess the inner array was the problem in the Magic Bossfight, and that this did not come up in the error message and/or I did not connect the dots…

Definitely edge for the time being, but maybe getting more mainstream now that @kwx has opened up pandoras’s box and shown us that it probably is possible to get near C64-quality music, and maybe even voice synthesis, in MakeCode with all the possibilities the envelopes give(programatically today and in the future with tools/extensions) and even more channels than the C64… :wink:

So if the fix is small, it might be a good investment!


  1. Do you or I create the issue on GitHub, if this is really necessary now?
  2. In the future, report stuff like this here or in an issue on GitHub. My impression is that it gets quicker @makecode response here and more community support, while they tend to drown away on GitHub…
    (…and here the users can more easily organize and gather around ad hoc user movements/campaigns, hehe…)
1 Like

Whichever works fine, I personally watch issues on github more carefully than forum (in pxt-arcade repo at least) but questions / non-bugs probably get more attention overall here. Also fine to do both (just crossreference them in the posts) so that more people can see it / pile on if they’re facing the the same issue!

Feel free to file an issue on github / reference this thread if you do, though I’ll say I find it unlikely that it’s a particularly quick fix – it feels like it’s in the “edge case upon edge case” scenario where tracking down a proper fix might be tough, but it’s good to track the issue for sure.

re: playing good music, we do have the upcoming song editor as well :slight_smile: (richard and I played around with it here – I would suggest that if people really want to use any of those it’s best to make a quick extension wrapping it as gray blocks are always a bit annoying / it’s easy to make blocks :slight_smile:

1 Like

Thanks again and forgot to thank you for the specific fix of my son’s Magic Bossfight, as well, which I kludged up the blocks on, attempting to help him with a little music just before the multiplayer mini game jam deadline… :wink:

On that note and good night from the old world:
Living on the edge

1 Like