美文网首页1024Learning TypescriptTypeScript基础
7、Typescript 数组接口、类接口

7、Typescript 数组接口、类接口

作者: 圆梦人生 | 来源:发表于2019-03-06 10:34 被阅读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');

相关文章

  • 7、Typescript 数组接口、类接口

    案例

  • Typescript接口、类

    一、接口 TypeScript的核心原则之一是对值所具有的结构进行类型检查。 它有时被称做“鸭式辨型法”或“结构性...

  • 【typeScript】:typeScript初学笔记(二)

    本周接着学习typeScript,上一次学习到接口,接口一般首字母大写。 数组 数组的表示方法: 1.「类型 + ...

  • TypeScript interface extends cla

    TypeScript 中接口也可以继承类,并且接口可以继承类中的各个成员包括protect和private成员。假...

  • TypeScript类与接口

    接口(Interfaces)可以用于对「对象的形状(Shape)」进行描述 类实现接口: 实现(implement...

  • TypeScript(四)类、接口

    认识类的使用 在早期的JavaScript开发中(ES5)我们需要通过函数和原型链来实现类和继承,从ES6开始,引...

  • No.3 List 有序集合

    List接口: (1)List是Collection接口的非抽象子接口,实现它的集合类有:ArrayList(数组...

  • Typescript学习概要

    大致印象 TypeScript 增加了静态类型、类、模块、接口和类型注解. TypeScript 可用于开发大型的...

  • 学习TypeScript 接口

    TypeScript 接口定义 interface interface_name {} 实例 联合类型和接口 接口...

  • Typescript

    安装 Typescript 接口 interface 约束类型结构、Duck Typing 类型推论、联合类型、类...

网友评论

    本文标题:7、Typescript 数组接口、类接口

    本文链接:https://www.haomeiwen.com/subject/gtttpqtx.html