Hi, thanks for sharing.
I've a doubt related to typescript.
How do I manage a single variable with having simultaneously two types?
For example:
product: Product | string;
where string version would denote productId. It would be very useful when fetching populated fields via mongoose.
Hi, thanks for sharing.
I've a doubt related to typescript.
How do I manage a single variable with having simultaneously two types?
For example:
product: Product | string;
where string version would denote productId. It would be very useful when fetching populated fields via mongoose.
good question! I think those two types are too vastly different to be in a union type and be useful.
I'd probably split it out to be
productId: string
andproduct: Product
and just convert one to the other if necessary.Okay I got it, thank you sir.