接口初探
export interface IColumns {
type: string;
}定义一个对象参数中含有type的属性
可选属性
export interface IColumns {
type?: string;
}只读属性
export interface IColumns {
readonly type?: string;
}断言重写
a = geyao as number[];
randonly和const
最简单判断该用readonly还是const的方法是看要把它做为变量使用还是做为一个属性。 做为变量使用的话用 const,若做为属性则使用readonly。
额外的属性检查
如果 SquareConfig带有上面定义的类型的color和width属性,并且还会带有任意数量的其它属性,
interface SquareConfig {
color?: string;
width?: number;
[propName: string]: any;
}参照官网文档进行学习









