# Errors

## 01

Missing samples in iterable. In order to let JTC know which values are valid for the iterables, you should push at least one sample to each iterable.

#### **Wrong**

```typescript
new ArrayMeta([] as any);
new MapMeta([] as any);
```

#### **Right**

```typescript
new ArrayMeta([new NumberField()]);
new MapMeta([new NumberField()]);
```

## 02

`builder` must create custom classes, not JS native

#### **Wrong**

```typescript
new ObjectMeta({ builder: Number, fields: {} });
```

#### **Right**

```typescript
class User {
   public id: string;
}

const USER_META = new ObjectMeta({
   builder: User,
   fields: {
      id: new StringField()
   }
});
```

## 03

Second attempt to define meta (new ObjectMeta) with already used builder

#### **Wrong**

```typescript
class User {
   public id: string;
}

const USER_META = new ObjectMeta({
   builder: User,
   fields: {
      id: new StringField()
   }
});

const USER_META_1 = new ObjectMeta({
   builder: User,
   fields: {
      id: new StringField()
   }
});
```

#### **Right**

```typescript
class User {
   public id: string;
}

const USER_META = new ObjectMeta({
   builder: User,
   fields: {
      id: new StringField()
   }
});
```

## 04

Iterable can have only one inner iterable entry

**Wrong**

```typescript
new ArrayMeta([
    new NumberArrayField(),
    new NumberArrayField(),
]);

new MapMeta([
    new NumberArrayField(),
    new NumberArrayField(),
]);
```

**Right**

```typescript
new ArrayMeta([
    new NumberArrayField(),
]);

new MapMeta([
    new NumberArrayField(),
]);
```

## 05

Meta for the parrent class should be created before creating meta for the child class

**Wrong**

```typescript
class Id {
   public id: string;
}

class User extends Id {
   public name: string;
}

new ObjectMeta({
   builder: User,
   fields: {
      id: new StringField(),
      name: new StringField(),
   }
});
```

**Right**

```typescript
class Id {
   public id: string;
}

const ID_META = new ObjectMeta({
   builder: Id,
   getId: ({ id }) => id,
   fields: {
      id: new StringField(),
   }
});

class User extends Id {
   public name: string;
}

new ObjectMeta({
   builder: User,
   fields: {
      id: new StringField(),
      name: new StringField(),
   }
});
```

## 06

Can't get meta from such value

`JTC.getMeta` will work only with instances which constructor was used during `new ObjectMeta` call. In all other cases error will be thrown.

#### **Wrong**

```typescript
class User {
   public id = ``;
   public isAdmin = false;
}

JTC.getMeta({});
JTC.getMeta(1);
JTC.getMeta(``);
JTC.getMeta(null);
JTC.getMeta(undefined);
JTC.getMeta(false);
JTC.getMeta(new User());

```

#### **Right**

```typescript
class User {
   public id: string;
}

const USER_META = new ObjectMeta({
   builder: User,
   fields: {
      id: new StringField()
   }
});

const meta = JTC.getMeta(new User());

console.log(meta === USER_META); // true
```
