0
点赞
收藏
分享

微信扫一扫

TS再读7-接口

接口初探

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;
}

参照官网文档进行学习



举报

相关推荐

0 条评论