Variable DtoConst

Dto: {
    BigIntValue: ((target, propertKey) => void);
    ChildDto: ((childClass) => ((target, propertyKey) => void));
    Int64String: ((target, propertyKey) => void);
    LosslessDto: typeof LosslessDto;
    createDtoInstance: (<T>(dtoClass, dtoData) => T);
} = ...

Type declaration

  • BigIntValue: ((target, propertKey) => void)
      • (target, propertKey): void
      • Decorate Dto bigint fields as @BigIntValue to specify that the JSON number property should be parsed as a bigint.

        Parameters

        • target: any
        • propertKey: string | symbol

        Returns void

        Example

        class MyDto extends LosslessDto {
        @Int64String
        int64NumberField!: string
        @BigIntValue
        bigintField!: bigint
        @ChildDto(MyChildDto)
        childDtoField!: MyChildDto
        normalField!: string
        normalNumberField!: number
        maybePresentField?: string
        }
  • ChildDto: ((childClass) => ((target, propertyKey) => void))
      • (childClass): ((target, propertyKey) => void)
      • Decorate a Dto object field as @ChildDto to specify that the JSON object property should be parsed as a child Dto.

        Parameters

        • childClass: any

        Returns ((target, propertyKey) => void)

          • (target, propertyKey): void
          • Parameters

            • target: any
            • propertyKey: string | symbol

            Returns void

        Example


        class MyChildDto extends LosslessDto {
        someField!: string
        }

        class MyDto extends LosslessDto {
        @Int64String
        int64NumberField!: string
        @BigIntValue
        bigintField!: bigint
        @ChildDto(MyChildDto)
        childDtoField!: MyChildDto
        normalField!: string
        normalNumberField!: number
        maybePresentField?: string
        }
  • Int64String: ((target, propertyKey) => void)
      • (target, propertyKey): void
      • Decorate Dto string fields as @Int64String to specify that the JSON number property should be parsed as a string.

        Parameters

        • target: any
        • propertyKey: string | symbol

        Returns void

        Example

        class MyDto extends LosslessDto {
        @Int64String
        int64NumberField!: string
        @BigIntValue
        bigintField!: bigint
        @ChildDto(MyChildDto)
        childDtoField!: MyChildDto
        normalField!: string
        normalNumberField!: number
        maybePresentField?: string
        }
  • LosslessDto: typeof LosslessDto
  • createDtoInstance: (<T>(dtoClass, dtoData) => T)
      • <T>(dtoClass, dtoData): T
      • Create an instance of a DTO class with the provided data.

        This provides a type-safe method to create a DTO instance from a plain object.

        Node 22's experimental strip types does not play well with the previous "via the constructor" method.

        See: https://gist.github.com/jwulf/6e7b093b5b7b3e12c7b76f55b9e4be84

        Type Parameters

        • T

        Parameters

        • dtoClass: (new () => T)
            • new (): T
            • Returns T

        • dtoData: T

        Returns T

Generated using TypeDoc