merge interface typescript code example
Example 1: typescript combine interfaces
interface IClientRequestAndCoords extends IClientRequest, ICoords {}
function(data: IClientRequestAndCoords)
interface ClientRequest {
userId: number
sessionKey: string
}
interface Coords {
lat: number
long: number
}
function log(data: ClientRequest & Coords) {
console.log(
data.userId,
data.sessionKey,
data.lat,
data.long
);
}
Example 2: typescript utility types merge interfaces
interface A {
x: string
}
interface B extends Omit<A, 'x'> {
x: number
}