How to handle union types in query parameters? #1732
-
Hey everyone! It seems I've got stuck with Ts.ED query parameter parsing. In particular I have a REST controller that accepts two types of the same query parameter:
The general idea to handle this is to have the following classes defined: class EntityDto {
createdAt?: Date | EntityFilter<Date>;
}
class EntityFilter<T> {
lte?: T;
} As you can see I have to check whether the So my questions is as follows: what decorators should I use to define such a distinction? And how should my |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can try to use the OnDeserialize decorator. It's not possible to automatically deserialize union type. @OnDeserialize(v => isObject(v) ? {lte: new Date(v.lte)} : new Date(v)) See you |
Beta Was this translation helpful? Give feedback.
You can try to use the OnDeserialize decorator. It's not possible to automatically deserialize union type.
See you