Skip to content

feature: make ClassTransformOptions extendable with custom options #625

Open
@dobromyslov

Description

@dobromyslov

Description

#238 feature allows us to add custom options to @Transform functions, but ClassTransformOptions interface itself does not allow to add custom options. See its current source here:

export interface ClassTransformOptions {

This also will be useful for #89.

Proposed solution

I think custom keys should be alowed in the interface like this:

export interface ClassTransformOptions {
  ...
  /** Additional custom options for Transform functions */
  [key: PropertyKey]: any;
}

or like this:

export interface ClassTransformOptions {
  ...
  /** Additional custom options for Transform functions */
  custom: Record<PropertyKey, any>;
}

or even like this:

export interface ClassTransformOptions<T = Record<PropertyKey, any>> {
  ...
  /** Additional custom options for Transform functions */
  custom: T;
}

Workaround

import {ClassTransformOptions as _ClassTransformOptions} from 'class-transformer/types/interfaces/class-transformer-options.interface';

export interface ClassTransformOptions extends _ClassTransformOptions {
  custom: {
    /**
     * Time zone, as specified by the IANA Time Zone Database.
     * Used for handling UTC timestamps in `toJSON()`.
     * Example: Europe/Moscow
     */
    timezone: string;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions