I have an interface defined like below:
export interface Iface {
id: string;
foo: string;
}
I want to create an interface that's a partial of Iface and export it. I tried
export interface PartialIface = Partial<Iface>;
but typescript complains of a partial error. If I change the interface keyword to type it works. How come I have to declare it as a type alias and not an interface?
export type PartialIface = Partial<Iface>;
Please take a look:
export interface Iface {
id: string;
foo: string;
}
export type PartialFace=Partial<Iface>
Also You can copy paste your interface and make all properties optional:
export interface Iface {
id?: string;
foo?: string;
}
I'm not aware about other approaches
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With