# Array type automatically switches to generic type when I move from Javascript to block code

**URL:** <https://forum.makecode.com/t/array-type-automatically-switches-to-generic-type-when-i-move-from-javascript-to-block-code/32277>\
**Category:** Help\
**Tags:** game\
**Created:** [December 6, 2024, 11:47pm UTC](https://forum.makecode.com/t/array-type-automatically-switches-to-generic-type-when-i-move-from-javascript-to-block-code/32277 "2024-12-06T23:47:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freastt](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/freastt/32/18481_2.png) [@Freastt](https://forum.makecode.com/u/Freastt)\
**Post date:** [December 6, 2024, 11:47pm UTC](https://forum.makecode.com/t/array-type-automatically-switches-to-generic-type-when-i-move-from-javascript-to-block-code/32277/1 "2024-12-06T23:47:13Z")

</div>

(I accidentally deleted my last post from before while trying to see how to edit it to add the ‘help’ tag sorry)

so I need the array in a parameter of a function to be specifically an ‘any’, which I specify it in Javascript

```auto
function interaction (dialog: any[]) {

```

but every time I move over to block-code, it automatically changes it back to the generic array type, which causes errors leading me to pause, go back to javascript, and test it over there

```auto
function interaction (dialog: Array[]) {

```

is there any workaround to this problem or am I just “SOL” as some may say 😅

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [December 6, 2024, 11:48pm UTC](https://forum.makecode.com/t/array-type-automatically-switches-to-generic-type-when-i-move-from-javascript-to-block-code/32277/2 "2024-12-06T23:48:40Z")

</div>

@Freastt can you share your code?

the type inference performed by our blockly compiler isn’t always the best where arrays are concerned. sometimes you can trick it into working though

---

<div class="post-metadata">

**Author:** ![Freastt](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/freastt/32/18481_2.png) [@Freastt](https://forum.makecode.com/u/Freastt)\
**Post date:** [December 8, 2024, 5:03am UTC](https://forum.makecode.com/t/array-type-automatically-switches-to-generic-type-when-i-move-from-javascript-to-block-code/32277/3 "2024-12-08T05:03:34Z")

</div>

no problemo, here’s a link to the current game as it is right now [https://arcade.makecode.com/S37861-42218-62759-21058](https://arcade.makecode.com/S37861-42218-62759-21058)

additionally, here’s also the specific function where the error is occuring

```auto
function interaction (dialog: Array[]) {
    while (!(DialogActive)) {
        timer.background(function () {
            DialogActive = true
        })
        controller.moveSprite(char, 0, 0)
        music.play(music.createSong(assets.song`mySong`), music.PlaybackMode.InBackground)
        TheBox = sprites.create(assets.image`logbox`, SpriteKind.Player)
        animation.runImageAnimation(
        TheBox,
        assets.animation`speechbubble`,
        150,
        true
        )
        TheBox.setFlag(SpriteFlag.RelativeToCamera, true)
        TheBox.setPosition(80, 140)
        spriteutils.moveTo(TheBox, spriteutils.pos(80, 98), 250, true)
        TheBox.z = 2
        char1 = sprites.create(assets.image`c1`, SpriteKind.Player)
        animation.runImageAnimation(
        char1,
        FreastLog.Char1(dialog[0]),
        200,
        true
        )
        char1.setFlag(SpriteFlag.RelativeToCamera, true)
        char1.setPosition(-60, 54)
        spriteutils.moveTo(char1, spriteutils.pos(24, 54), 250, false)
        char2 = sprites.create(assets.image`c0`, SpriteKind.Player)
        animation.runImageAnimation(
        char2,
        FreastLog.Char2(dialog[0]),
        200,
        true
        )
        char2.setFlag(SpriteFlag.RelativeToCamera, true)
        char2.setPosition(200, 54)
        spriteutils.moveTo(char2, spriteutils.pos(136, 54), 250, true)
        NamePlate = sprites.create(assets.image`CharBox`, SpriteKind.Player)
        animation.runImageAnimation(
        NamePlate,
        assets.animation`namePlate`,
        150,
        true
        )
        NamePlate.setPosition(32, 76)
        NamePlate.setFlag(SpriteFlag.RelativeToCamera, true)
        nameText = textsprite.create("", 0, 13)
        nameText.setFlag(SpriteFlag.RelativeToCamera, true)
        nameText.setPosition(7, 75)
        nameText.z = 4
        NamePlate.z = 3
        char2.z = 1
        char1.z = 1
        story.setSoundEnabled(true)
        for (let index = 0; index <= dialog.length - 1; index++) {
            if (FreastLog.Priority(dialog[index]) == 0) {
                char1.setScale(1.05, ScaleAnchor.Middle)
                char1.y = 48
                char2.setScale(0.8, ScaleAnchor.Middle)
                char2.y = 54
            } else {
                char2.setScale(1.05, ScaleAnchor.Middle)
                char2.y = 48
                char1.setScale(0.8, ScaleAnchor.Middle)
                char1.y = 54
            }
            animation.runImageAnimation(
            char1,
            FreastLog.Char1(dialog[index]),
            200,
            true
            )
            animation.runImageAnimation(
            char2,
            FreastLog.Char2(dialog[index]),
            200,
            true
            )
            nameText.setText(FreastLog.Name(dialog[index]))
            story.printDialog(FreastLog.Dialog(dialog[index]), 80, 100, 40, 150, 6, 0, story.TextSpeed.VeryFast)
        }
        sprites.destroy(nameText)
        sprites.destroy(NamePlate)
        controller.moveSprite(char, 100, 100)
        spriteutils.moveTo(char1, spriteutils.pos(0, 60), 100, true)
        sprites.destroy(char1)
        spriteutils.moveTo(char2, spriteutils.pos(160, 60), 100, true)
        sprites.destroy(char2)
        spriteutils.moveTo(TheBox, spriteutils.pos(80, 140), 100, true)
        sprites.destroy(TheBox)
        TheBox.z = 0
        timer.background(function () {
            pauseUntil(() => spriteutils.isDestroyed(TheBox))
            DialogActive = false
        })
    }
}

```

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [December 9, 2024, 5:59pm UTC](https://forum.makecode.com/t/array-type-automatically-switches-to-generic-type-when-i-move-from-javascript-to-block-code/32277/4 "2024-12-09T17:59:28Z")

</div>

@Freastt i think the easiest fix here would be to change your FreastLog.Log function to return a custom type instead of an away of multiple types as you’re doing now.

for example:

```typescript
namespace FreastLog {
    export class LogEntry {
        constructor(
                public name: string,
                public dialog: string,
                public char1: Image[],
                public char2: Image[],
                public priority: number
        ) {}
    }

    //% block    
    export function Log(name: string, dialog: string, c1: Array<Image>, c2: Array<Image>, p: number): LogEntry 
    {
        return new LogEntry(name, dialog, c1, c2, p);
    }

    //% block
    export function Name(dialogue: LogEntry): string {
        return dialogue.name
    }

    //% block
    export function Dialog(dialogue: LogEntry): string {
        return dialogue.dialog
    }

    //% block
    export function Char1(dialogue: LogEntry): Image[] {
        return dialogue.char1
    }

    //% block
    export function Char2(dialogue: LogEntry): Image[] {
        return dialogue.char2;
    }

    //% block
    export function Priority(dialogue: LogEntry): number {
        return dialogue.priority;
    }
}

```

then change the type of your other function to `LogEntry[]` instead of `any[]`
