Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface MainDecorator

Hierarchy

  • MainDecorator

Index

Methods

any

  • Marks a field as type any. It does not transform the value and directly uses JSON.parse/stringify.

    Returns FieldDecoratorResult<any>

array

  • Marks a field as array.

    class User {
        @f.array(String)
        tags: string[] = [];
    }

    Type parameters

    Parameters

    Returns FieldDecoratorResult<T>

discriminant

  • Marks a field as discriminant. This field MUST have a default value. The default value is used to discriminate this class type when used in a union type. See @f.union.

    Type parameters

    • T

    Returns FieldDecoratorResult<T>

enum

  • Marks a field as enum.

    enum MyEnum {
        low;
        medium;
        hight;
    }
    
    class User {
        @f.enum(MyEnum)
        level: MyEnum = MyEnum.low;
    }

    If allowLabelsAsValue is set, you can use the enum labels as well for setting the property value using plainToClass().

    Type parameters

    • T

    Parameters

    • type: T
    • Optional allowLabelsAsValue: undefined | false | true

    Returns FieldDecoratorResult<T>

forward

  • Forward references a type, required for circular reference.

    class User {
        @f.forward(() => User)).optional()
        parent: User;
    }

    Type parameters

    • T: ClassType<any>

    Parameters

    • f: () => T
        • (): T
        • Returns T

    Returns FieldDecoratorResult<T>

forwardArray

  • Forward references a type in an array, required for circular reference.

    class User {
        @f.forwardArray(() => User)).optional()
        parents: User[] = [];
    }

    Type parameters

    • T: ClassType<any>

    Parameters

    • f: () => T
        • (): T
        • Returns T

    Returns FieldDecoratorResult<T>

forwardMap

  • Forward references a type in a map, required for circular reference.

    class User {
        @f.forwardRef(() => User)).optional()
        parents: {[name: string]: User} = {}};
    }

    Type parameters

    • T: ClassType<any>

    Parameters

    • f: () => T
        • (): T
        • Returns T

    Returns FieldDecoratorResult<T>

forwardPartial

  • Marks a field as partial of a class entity.

    class Config {
        @f.optional()
        name?: string;
    
        @f
        prio: number = 0;
    }
    
    class User {
        @f.forwardPartial(() => Config)
        config: PartialField<Config> = {};
    }

    Type parameters

    • T: ClassType<any>

    Parameters

    • type: () => T
        • (): T
        • Returns T

    Returns FieldDecoratorResult<T>

map

  • Marks a field as map.

    class User {
        @f.map(String)
        tags: {[k: string]: string};
    
        @f.forwardMap(() => MyClass)
        tags: {[k: string]: MyClass};
    }

    Type parameters

    Parameters

    Returns FieldDecoratorResult<T>

moment

  • Marks a field as Moment.js value. Mongo and JSON transparent uses its toJSON() result. In MongoDB its stored as Date.

    You have to install moment npm package in order to use it.

    Returns FieldDecoratorResult<any>

partial

  • Marks a field as partial of a class entity. It differs in a way to standard Partial<> that it allows path based sub values, like you know from JSON patch.

    class Config {
        @f.optional()
        name?: string;
    
        @f.optional()
        sub?: Config;
    
        @f
        prio: number = 0;
    }
    
    class User {
        @f.partial(Config)
        config: PartialField<Config> = {};
    }

    Type parameters

    • T: ClassType<any>

    Parameters

    • type: T

    Returns FieldDecoratorResult<T>

type

  • Defines a type for a certain field. This is only necessary for custom classes if the Typescript compiler does not include the reflection type in the build output.

    class User {
        @f.type(MyClass)
        tags: MyClass = new MyClass;
    }

    Type parameters

    Parameters

    • type: T

    Returns FieldDecoratorResult<T>

union

  • Defines discriminated union types.

    class ConfigA {
        @f.discriminator()
        kind: string = 'a';
    
        @f
        myValue: string = '';
    }
    
    class ConfigB {
        @f.discriminator()
        kind: string = 'b';
    
        @f
        myValue2: string = '';
    }
    
    class User {
        @f.types(ConfigA, ConfigB)
        config: ConfigA | ConfigB = new ConfigA;
    }

    Type parameters

    Parameters

    • Rest ...type: T[] | K[]

    Returns FieldDecoratorResult<void>

Generated using TypeDoc