I want to have the parameters of a method that is part of an interface adhere to another interface.
Consider this IOrderBuilder
interface which I use to build Order
object from a class that is implementing it.
interface IOrderBuilder {
setCustomer({ customerId }: { customerId: string; }): Order;
// ...other methods
setShippingAddress(address: IAddress): Order;
// ...other methods
}
IAddress
is also an interface –
interface IAddress {
name: string;
addressLine1: string;
addressLine2: string;
landmark: string;
city: string;
state: string;
pincode: number;
}
Now what I want is to have an interface let’s say IShippingAddressParams
, properties of whose are used as types for parameters of setShippingAddress
method.
When I do it like this –
interface IShippingAddressParams {
address: IAddress;
}
interface IOrderBuilder {
setCustomer({ customerId }: { customerId: string; }): Order;
// ...other methods
setShippingAddress(params: IShippingAddressParams): Order;
// ...other methods
}
In this case, I would need to pass an object while defining my setShippingAddress
method like this – setShippingAddress(shippingParams: {address: IAddress}) {...}
.
Instead, what I want is to be able to pass address directly like this – setShippingAddress(address: IAddress) {...}
.