1024Learning TypescriptTypeScript基础

7、Typescript 数组接口、类接口

2019-03-06  本文已影响1人  圆梦人生

案例

// 1、数组接口
interface ArrayInterface {
    // 索引index是必须的
    [index:number]:string;
}
let arrayInfo:ArrayInterface = ['a', 'b', 'c'];
console.log(arrayInfo);

// 2、定义接口
interface ClassInterface {
    // 定义方法
    showInfo(str:string):any
}

class ClasOne implements ClassInterface {
    // 实现接口方法
    showInfo(str:string){
        console.log('ClasOne====' + str);
    }
}
class ClassTwo implements ClassInterface {
    // 实现接口方法
    showInfo(str:string){
        console.log('ClassTwo====' + str);
    }
}

let c1 = new ClasOne();
c1.showInfo('zs');
let c2 = new ClassTwo();
c2.showInfo('lis');
上一篇下一篇

猜你喜欢

热点阅读