作为函数的参数类型的定义
interface labelobj{label:string}function printLabel(lableObject: labelobj){console.log(lableObject)}printLabel({label:"label"})
参数后面加上?表示可选参数
interface labelobj{label:stringwidth?: number}function printLabel(lableObject: labelobj){console.log(lableObject)}printLabel({label:"label"})printLabel({label:'abc',width:10})
readonly 不能修改的值
interface Point{readonly x:numberreadonly y:number}let p1:Point = {x:10,y:5}p1.x = 20 // Cannot assign to 'x' because it is a read-only property.
