You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a class that has three properties: "type", "data" and "metadata". Based on the value of "type" I am transforming "data" and "metadata" to different classes. I am using the @Type decorator with a function that returns different classes with a switch-case on "type" (I don't think I can use a normal discriminator because the "type" property is not inside "data" or "metadata", and I can't use @type on the whole class). I want to skip transformation on "data" or "metadata" when "type" is equal to some value. I want the property to be in the transformed class as a plain object (mostly for logging purposes, I'll just dump the value into the log).
The problem:
I don't know of a way to return an "unknown" value in the @Type decorator callback. The callback only returns a Function and when trying to return something like (value: unknown) => value I got the error "Cannot read properties of undefined (reading 'constructor')", which probably means it only accepts classes. I want to support any value (string, boolean, number, Record<string, unknown>), but I could not find a way to achieve this.
The text was updated successfully, but these errors were encountered:
I have a class that has three properties: "type", "data" and "metadata". Based on the value of "type" I am transforming "data" and "metadata" to different classes. I am using the
@Type
decorator with a function that returns different classes with a switch-case on "type" (I don't think I can use a normal discriminator because the "type" property is not inside "data" or "metadata", and I can't use@type
on the whole class). I want to skip transformation on "data" or "metadata" when "type" is equal to some value. I want the property to be in the transformed class as a plain object (mostly for logging purposes, I'll just dump the value into the log).The problem:
I don't know of a way to return an "unknown" value in the
@Type
decorator callback. The callback only returns aFunction
and when trying to return something like(value: unknown) => value
I got the error "Cannot read properties of undefined (reading 'constructor')", which probably means it only accepts classes. I want to support any value (string, boolean, number, Record<string, unknown>), but I could not find a way to achieve this.The text was updated successfully, but these errors were encountered: