Class AutoObject<T>Abstract

Description

Auto initialized object

Example

class Geo extends Array<number> {}

class Address extends AutoObject<Address> {
@IsString()
public city: string;

@IsString()
public street: string;

@IsNumber()
public apartment: number;

@IsNumber()
public postal: number;

@IsArray()
public geo: Geo;

public get inline() {
return <Getter<string>>(
`${this.postal}, ${this.city}, ${this.street}${this.apartment}`
);
}
}

class User extends AutoObject<User> {
@IsInt()
public id: number;

@IsString()
public firstName: string;

@IsString()
public lastName: string;

@IsObject()
@ValueObject(Address)
public address: Address;
}

const user = new User({
id: 1,
firstName: 'Vasya',
lastName: 'Pupkin',
address: {
city: 'Moscow',
street: 'Gogolya',
postal: 123321,
apartment: 74,
geo: [12321, 32123],
},
});

console.log(user); // User {
// "address": Address {
// "city": "Moscow",
// "apartment": 74,
// "geo": Array [
// 12321,
// 32123,
// ],
// "postal": 123321,
// "street": "Gogolya",
// },
// "firstName": "Vasya",
// "id": 1,
// "lastName": "Pupkin",
// }

Type Parameters

  • T = Record<string, any>

Hierarchy

  • AutoObject

Constructors

Methods

Constructors

Methods

  • Type Parameters

    • C extends (new (...args) => any)

    • T = Record<string, any>

    Parameters

    • Class: C

    Returns {
        prototype: __type<any, any, any>;
        new (...args): __type<T, C, T>;
    } & C

Generated using TypeDoc