# 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:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hasanchik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/hasanchik/32/5885_2.png) [@hasanchik](https://forum.makecode.com/u/hasanchik)
#### Post date: [April 6, 2022, 5:53pm UTC](https://forum.makecode.com/t/why-doesnt-this-work/12991/1 "2022-04-06T17:53:26Z")

</div>

```auto
if (a instanceof Image) {

}

```

why doesn’t this work 😑

‘Image’ only refers to a type, but is being used as a value here

---

<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: [April 6, 2022, 8:22pm UTC](https://forum.makecode.com/t/why-doesnt-this-work/12991/2 "2022-04-06T20:22:35Z")

</div>

Why do you want to know a variable’s type?

Variables are restricted to one\* type only.

\* Well, unless you need to use `Any` for some reason.

---

<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)

```

---

<div class="post-metadata">

### Author: ![hasanchik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/hasanchik/32/5885_2.png) [@hasanchik](https://forum.makecode.com/u/hasanchik)
#### Post date: [April 7, 2022, 3:30pm UTC](https://forum.makecode.com/t/why-doesnt-this-work/12991/4 "2022-04-07T15:30:23Z")

</div>

Didn’t realize all those drawicon errors from before could teach me anything.

Also didn’t realize a image was a interface.  
Thanks!

---

<div class="post-metadata">

### Author: ![hasanchik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/hasanchik/32/5885_2.png) [@hasanchik](https://forum.makecode.com/u/hasanchik)
#### Post date: [April 7, 2022, 3:30pm UTC](https://forum.makecode.com/t/why-doesnt-this-work/12991/5 "2022-04-07T15:30:26Z")

</div>

…i have my reasons
