# 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
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
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
2
3
4
5
6
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Jest
- Seq
- Controllers
- Providers
- Model
- Converters
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing