# CollectionOf Decorator validation jsonMapper schema property collections alias

Module
import { CollectionOf } from "@tsed/common"
Source/packages/common/src/jsonschema/decorators/propertyType.ts

# Overview

function CollectionOf(type: Type<any>): Function;

# Description

Set the type of the array items. The possible value is String, Boolean, Number, Date, Object, Class, etc...

TIP

This decorator is used by the Converters to correctly deserialize your model.

class Model {
   @CollectionOf(String)
   property: string[];
}
1
2
3
4

WARNING

Don't use type Type = string | number as Type parameter.

The following code doesn't work:

type Type = "string" | "number"
class Model {
   @CollectionOf(Type)
   property: Type[];
}
1
2
3
4
5

Instead, this code works with converter and AJV:

type Type = "string" | "number"
class Model {
   @Property()
   @AllowTypes("string", "number") // for AJV
   property: Type[];
}
1
2
3
4
5
6