# What is / When to use an interface?

**URL:** https://forum.makecode.com/t/what-is-when-to-use-an-interface/31418
**Category:** Help
**Created:** [October 30, 2024, 7:54pm UTC](https://forum.makecode.com/t/what-is-when-to-use-an-interface/31418 "2024-10-30T19:54:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![SenseiDixon](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@SenseiDixon](https://forum.makecode.com/u/SenseiDixon)
#### Post date: [October 30, 2024, 7:54pm UTC](https://forum.makecode.com/t/what-is-when-to-use-an-interface/31418/1 "2024-10-30T19:54:00Z")

</div>

I’m used to vanilla JavaScript but not TypeScript. I had need to do the following:

> let tileMap = {  
> width: 32,  
> height: 32,  
> tiles:   
> }  
> I would then store the tiles of a tilemap in that array. However TypeScript does not let me use an array with no type definition. The closest I could get to making this work was by using an interface.

```auto
interface tileMapSave {
    name : "",
    width: 32,
    height: 32,
    tiles: Image[]
}

let tileMap: tileMapSave

```

But I’m left wondering if this is the appropriate use of an interface and if there is a different typescript way of creating the object I want. Any clarification would be useful as I’m feeling rather fuzzy-headed about this. Is an interface just for forcing me to make random objects I make have a “type”?

---

<div class="post-metadata">

### Author: ![WoofWoof](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/woofwoof/32/32523_2.png) [@WoofWoof](https://forum.makecode.com/u/WoofWoof)
#### Post date: [October 30, 2024, 9:02pm UTC](https://forum.makecode.com/t/what-is-when-to-use-an-interface/31418/2 "2024-10-30T21:02:28Z")

</div>

What are you trying to store, exactly? Are you trying to implement your own version of the built in tilemap functionality? Are you trying to store the image of each tile? The type of tile? The location? Or are you trying to store a combination of these?

---

<div class="post-metadata">

### Author: ![Sarge](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/sarge/32/19590_2.png) [@Sarge](https://forum.makecode.com/u/Sarge)
#### Post date: [October 31, 2024, 2:03am UTC](https://forum.makecode.com/t/what-is-when-to-use-an-interface/31418/3 "2024-10-31T02:03:58Z")

</div>

Essentially, yes. This is the “TypeScript way” of doing things. Normally you can omit the type but since you have an array in your object it requires a generic type. And since you can’t add a type for only one property (for some reason) you have to type out the whole object, for which the easiest method is an interface.

---

<div class="post-metadata">

### Author: ![SenseiDixon](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@SenseiDixon](https://forum.makecode.com/u/SenseiDixon)
#### Post date: [November 1, 2024, 10:34pm UTC](https://forum.makecode.com/t/what-is-when-to-use-an-interface/31418/4 "2024-11-01T22:34:21Z")

</div>

In my game the player can change the tiles of a tilemap. I want to be able to save these alterations between scenes. Im sure there are other ways to do it - the specific implementation isnt so important right now, I’m just trying to understand TypeScript.
