# AllowTypes Decorator

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

# Overview

function AllowTypes(type: JSONSchema6TypeName, ...types: JSONSchema6TypeName[]): (...parameters: any[]) => any;

# Description

Set the type of the array items.

# Example

# With multiple types

class Model {
   @AllowTypes("string", "number", "boolean", "array")
   property: "string" | "number" | "boolean" | "array";
}
1
2
3
4

Will produce:

{
  "type": "object",
  "properties": {
    "property": {
      "type": ["string", "number", "boolean", "array"]
    }
  }
}
1
2
3
4
5
6
7
8

# With array of multiple types

class Model {
   @AllowTypes("string", "number", "boolean", "array")
   property: ("string" | "number" | "boolean" | "array")[];
}
1
2
3
4

Will produce:

{
  "type": "object",
  "properties": {
    "property": {
      "type": "array",
      "items": {
         "type": ["string", "number", "boolean", "array"]
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11