zl程序教程

您现在的位置是:首页 >  其他

当前栏目

ts 索引签名 无视多余的属性类型

属性索引 类型 签名 TS 多余
2023-09-14 08:58:45 时间
interface SquareConfig {
    color?: string;
    width?: number;
    [propName: string]: any;
}

function asd(opt: SquareConfig): any {
}

asd({color: 'red', width: 2, name: 'asd', age: 14})  // 只关心 color和width的类型是否正确,其它属性不错检测