It is currently impossible to check if an object is a certain type/weird iface error

Hi there. I have a weird problem going on when trying to make my platformer game. In my game I need to check if an object is my custom animation class or the default image class. Makecode Arcade really does not want me to do this though for some reason. I’ve tried every trick in the book. I will be listing each method under here with their corresponding errors. Could anyone please help me with this?

Method 1:

function IsObjectAnimation(object: any): object is Animation {
  return 'delayPerFrame' in object && 'animationState' in object

Error: (roughly) “In” is an unsupported operator

Method 2:

function IsObjectAnimation(object: any): boolean {
  if (object.hasOwnProperty("delayPerFrame") && object.hasOwnProperty("animationState")) {
    return true
  return false

“Error”: The simulator does not want to start, it just crashes and halts without spitting any errors

Method 3:

function IsObjectAnimation(object: any): object is Animation {
  return typeof object.isAnimation === 'boolean'

Error: ‘Cannot read properties of undefined (reading ‘iface’)
at (line 2)’
(Test code i was using:

let image: Image = image.create(8, 8)

These issues could all be fixed by updating to a newer version of typescript, although that can cause some problems. I don't know if that is feasible but if it is you should upgrade the language to a newer version to avoid causing headaches like this lol

you could try downloading an animation extension

I’ve dealt with this issue before. i think you’re looking for

object isinstance <your custom class here>

It’s a method that works for me and it should correctly check if some object is of that type. It’s also way more practical than checking for properties

1 Like