Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use typia with generic functions (Angular, TypeScript) #941

Closed
deyan-peychev opened this issue Jan 25, 2024 · 1 comment
Closed
Assignees
Labels
duplicate This issue or pull request already exists

Comments

@deyan-peychev
Copy link

I have an Angular application and I'm creating a PayloadValidationService which has a generic function that uses typia's validateEqual to validate objects:

import { Injectable } from "@angular/core";
import typia from "typia";

@Injectable({
  providedIn: 'root'
})
export class PayloadValidationService {

  validatePayload<T>(payload: object): void {
    console.log(typia.validateEquals<T>(payload)); // There will be additional functionality if the result is an error
  }

}

I am using the function as follows:

interface MyPayload {
    someValue: string;
}

@Injectable({
    providedIn: 'root'
})
export class MyService {

    constructor(private payloadValidationService: PayloadValidationService) {}
    
    myApiRequest(data: any) {
        this.payloadValidationService.validatePayload<MyPayload>(data);

        // ... 
    }
}

This throws the following error in the console:

ERROR Error: Error on typia.validateEquals(): no transform has been configured. Read and follow https://typia.io/docs/setup please.

If I use the validateEquals directly with my interface and not use generics (e.g. typia.validateEquals<MyPayload>(data)), everything works normally without any errors.

Is there any way to make it work with generics?


Angular version: 17
Typia version: "^5.4.0"
I have run npm install typia and npx typia setup

@samchon samchon self-assigned this Jan 26, 2024
@samchon samchon added the duplicate This issue or pull request already exists label Jan 26, 2024
@samchon
Copy link
Owner

samchon commented Jan 26, 2024

Too much duplicated question, and not possible to do it.

To accomplish the feature, I've to remake Typia and TypeScript compiler entirely.

Utilize typia.createAssert<T>() like functions intead please.

@samchon samchon closed this as not planned Won't fix, can't repro, duplicate, stale Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants