# Motoko \<\>Typescript : Array

**URL:** <https://forum.dfinity.org/t/motoko-typescript-array/14040>\
**Category:** Developers\
**Created:** [June 26, 2022, 10:14am UTC](https://forum.dfinity.org/t/motoko-typescript-array/14040 "2022-06-26T10:14:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyan](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/kyan/32/6488_2.png) [@Kyan](https://forum.dfinity.org/u/Kyan)\
**Post date:** [June 26, 2022, 10:14am UTC](https://forum.dfinity.org/t/motoko-typescript-array/14040/1 "2022-06-26T10:14:01Z")

</div>

Hello community, I’m facing a misunderstanding with arrays from Motoko and Typescript.

Here is the problem:

```auto
// Motoko file
public type Entity = {
	tagList: ?[Text];
};

```

```auto
// Generated Typescript file
export interface Entity {
	'tagList': [] | [Array<string>]
};

```

And now the problems I’m facing in my Typescript frontend file :

```auto
/**
 * IDE Error :
 * Type 'string[]' is not assignable to type '[] | [string[]]'.
 */
public buildEntity(tagList: string[]): void {
	const entity: Entity = {
		tagList: tagList
	};
};

```

```auto
/**
 * Not used, just to test
 * IDE Error :
 * Type '{ tagList: [string[]]; }' is missing the following properties from type 'Entity'
 */
public buildEntity(tagList: [string[]]): void {
	const entity: Entity = {
		tagList: tagList
	};
};

```

```auto
/**
 * Runtime Error :
 * Invalid opt record {tagList:opt vec text;} argument: [{"tagList":["tag1","tag2"]}]
 */
public buildEntity(tagList: []): void {
	const entity: Entity = {
		tagList: tagList
	};
};

```

Coming from Java, I am used to strong typing and I wonder if the problem does not come from there… Or maybe I missed something that is right in front of my eyes.

Could someone give me some help on this problem?

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [June 26, 2022, 11:45am UTC](https://forum.dfinity.org/t/motoko-typescript-array/14040/2 "2022-06-26T11:45:34Z")

</div>

The js agent uses arrays to handle opt values. if you have an opt array you need to look for an array in an array.

would be null  
[] would be an empty array  
[[val,val]] would be an array with data in it

---

<div class="post-metadata">

**Author:** ![Kyan](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/kyan/32/6488_2.png) [@Kyan](https://forum.dfinity.org/u/Kyan)\
**Post date:** [June 26, 2022, 11:47am UTC](https://forum.dfinity.org/t/motoko-typescript-array/14040/3 "2022-06-26T11:47:58Z")

</div>

Ok I solved the problem by removing the optional syntax from the Motoko tagList field.

```auto
// Motoko file
public type Entity = {
	tagList: [Text];
};

```

```auto
// Generatered Typescript file
export interface Entity {
    'tagList' : Array<string>,
};

```

In the end, it seems more relevant to have an empty Array rather than a null one.
