In the below typescript program, I am applying conditional type chaining to display the outcome on the output console. Conditional types can get chained together to return a specific type.
interface IHomeAppliance {
table : number;
}
interface IComputerAppliance {
table : number;
brand : string;
}
type home_computer<T> =
T extends IComputerAppliance ? [number, string] :
T extends IHomeAppliance ? [number] :
never;
function getHomeComputer<T> (tuplevalue : home_computer<T>) : string {
let [...tupleList] = tuplevalue
let description = " "
for(let value of tupleList) {
description += value + " "
}
return description
}
let homecomputer = getHomeComputer<IComputerAppliance>([3, "XYZ"])
console.log("The number of table and computer brand are" + homecomputer)
The outcome of the program is as follows:-
The number of table and computer brand are 3 XYZ