# Why doesnt this work :|

**URL:** https://forum.makecode.com/t/why-doesnt-this-work/12991
**Category:** Arcade
**Created:** [April 6, 2022, 5:53pm UTC](https://forum.makecode.com/t/why-doesnt-this-work/12991 "2022-04-06T17:53:25Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![AlexK](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/alexk/32/33339_2.png) [@AlexK](https://forum.makecode.com/u/AlexK)
#### Post date: [April 6, 2022, 8:27pm UTC](https://forum.makecode.com/t/why-doesnt-this-work/12991/3 "2022-04-06T20:27:09Z")

</div>

Interesting, @hasanchik . `Image` is an interface, not a class, and `instanceof` does not work with interfaces in TypeScript.

The traditional way to deal with this is to typecast the variable and check for an interesting method. That, though, does not work in MakeCode.

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

So, the next best thing is to check for an interesting attribute instead. This works:

```typescript
let a: Image = img`.`
let b: number = 42
let msg: string = ""

function testImage(i: any): boolean {
    if ((<Image>i).width) {
        return true
    } else {
        return false
    }
}

if (testImage(a)) {
    msg += "a is an image!"
} else {
    msg += "a is not an image"
}

if (testImage(b)) {
    msg += "; b is an image!"
} else {
    msg += "; b is not an image!"
}

game.splash(msg)

```

---

_[View the full topic](https://forum.makecode.com/t/why-doesnt-this-work/12991)._
