Skip to content

New Function to Perform Class Transformation #683

Description

@benoit-scnd

Feature Request

A new function named classTransform that converts a given input into an instance of a specific class.

The function could have the following signature:

typia.classTransform<T>(input: Primitive<T>): T;

This function takes two arguments:

  • input: The primitive input to be converted.
  • T: The target class that the input should be transformed into.

The function should return an instance of the class T with the given input.

This function would be particularly useful for converting raw input data into class instances. This issue is critical as it prevents proper type validation and transformation of the incoming request body, a common requirement in type-safe server-side applications. (see samchon/nestia#431)

Example Usage

Here is an example of how this function could be used:

class Foo {
  constructor(public value: string) {}

  bar() {
    return this.value;
  }
}

const input = {value: "test"};
const transformed = typia.classTransform<Test>(input);
console.log(transformed.bar()); // Should log: "test"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions