TypeScript接口
注:TYPESCRIPT的接口是可以直接使用的,不像C#中需要一个类继承
interface Televersion {
name: string,
height: number,
width: number,
}
interface OledTeleversion extends Televersion {
price?: number
}
let SonyTV: OledTeleversion =
{
name: 'Sony',
height: 1080,
width: 1920,
price: 900
}
function PrintTV(thisTV: OledTeleversion) {
console.log(`名稱:${thisTV.name}`);
console.log(`高:${thisTV.height}`);
console.log(`寬:${thisTV.width}`);
console.log(`價格:${thisTV.price}`);
}
PrintTV(SonyTV);