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

question: Use strategy: 'excludeAll' with some explicitly untyped data #1730

Open
Cyberuben opened this issue Jul 15, 2024 · 1 comment
Open
Labels
type: question Questions about the usage of the library.

Comments

@Cyberuben
Copy link

I was trying to...
Almost all of my code is typed properly, with DTOs and validation on input data. All my responses are either mapped to entities (from TypeORM), or DTOs which I explicitly convert to these DTOs before returning them as plain objects again, to prevent fields that I don't want public from leaking out.

Now I'm dealing with some data which I'm not able to build the typing for, as it is calling an external API and passing through the response. I want to return this data anyway.

The problem:
https://stackblitz.com/edit/typescript-playground-ec9vct?file=index.ts

In the code above, you can see that the object in both stages is just an empty object. How can I have class transformer accept that this is untyped data?

@Cyberuben Cyberuben added the type: question Questions about the usage of the library. label Jul 15, 2024
@diffy0712
Copy link

Hello @Cyberuben,

it seems that when excludeAll strategy is used, the value does not contain the nested object for some reason. This might be a bug, I have to look at this a bit if I have time.

But to answer your question. You can use the following transform @Transform(({key, obj}) => obj[key]).

Hope this helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Questions about the usage of the library.
Development

No branches or pull requests

2 participants