ts add two types code example
Example 1: merge two types typescript
interface IStudent {
id: string;
age: number;
}
interface IWorker {
companyId: string;
}
type IStudentAlias = IStudent;
type ICustomType = IStudent | IWorker;
let s: IStudentAlias = {
id: 'ID3241',
age: 2
};
Example 2: 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
);
}