type-fest
type-fest copied to clipboard
Question: is there any way to get the advantages of opaque and other options at the same time?
given
export type OrderPart = SetRequired<Except<Partial<OrderEntity>, 'id'>, 'orderId'>;
export type OrderOnly = Opaque<OrderPart>;
export class OrderAggregateFactory {
constructor(private readonly em: EntityManager) {}
order(part: OrderOnly): Promise<OrderEntity> {
if I use it like this... I get the benefits of both
const orderPart: OrderPart = {
status: OrderStatus.Open,
orderId,
};
return new OrderAggregateFactory(em).order(orderPart as OrderOnly);
but if I write like the latter, I lose the benefits of SetRequired
, and probably other things (this compies)
return new OrderAggregateFactory(em).order({
status: OrderStatus.Open,
} as OrderOnly);
is their a way to write it "like" the latter example? but still have Required and other things cause compile errors?