/*
接口 C#写多了,接口也自然也是理解的。不过TypeScript中的接口与
C#中的还是有些区别的
接口的作用就是为这些类型命名和为你的代码或第三方代码定义契约
*/ //为方法的参数做契约
interface IPersion {
Name: string;
Age: number;
}
function fun6(person: IPersion): void { };
//参数必须满足接口 IPerson 多一个少一个都不行,属性名写错也不
//行 Name 不可以写成 SName
fun6({ Name: "jack", Age: 26, Other: 5 }); //可空属性 ? 比如Name?
//只读属性 readonly 比如 readonly Name; Nmae只会在初始化的时
//候赋值 Arrary类型有个 ReadonlyArray //用接口来描述函数
interface SearchFun {
(source: string, subString: string): boolean;
}
let mySearch: SearchFun;
//签名个数类型必须一致,但名称可以不一致
mySearch = function (mysource: string, mysubString: string) {
let result = mysource.search(mysubString);
return result != -1;
} //索引 除了数字还可以使用字符串做签名,如果同时使用数字和字符
//串做索引,那么数字返回的类型必须是字符串的子类型或者是同类
//型。也就两者的类型需要一致
interface StringArrary {
[index: number]: string;
}
//其实这是多余的
let myArray: StringArrary;
myArray = ["jack", "yuhan"];
myArray[0]; //实现接口,与C#一致了,面向接口的开发的好处相信大家都是知道的
//TypeScript中使用 implements 关键字
class Person implements IPersion {
Name;
Age;
} //扩展接口
interface Shape {
Color: string;
} interface Square extends Shape {
SideLength: number;
} let square = <Square>{};
square.SideLength = 10;
square.Color = "red"; //接口继承类 真是乱-.-

TypeScript 素描 - 接口的更多相关文章

  1. TypeScript 素描-基础类型

    博文读自 TypeScript 官方文档而来,不具有学习性,仅是本人学习时记录以供日后翻阅 ,有学习TypeScript的朋友还请去看更为详细的官方文档 TypeScript官网文档中的基础类型, T ...

  2. TypeScript入门五:TypeScript的接口

    TypeScript接口的基本使用 TypeScript函数类型接口 TypeScript可索引类型接口 TypeScript类类型接口 TypeScript接口与继承 一.TypeScript接口的 ...

  3. TypeScript之接口类型

    Interfaces 作为TypeScript中的核心特色之一,能够让类型检查帮助我们知道一个对象应该有什么,相比我们在编写JavaScript的时候经常遇到函数需要传递参数,可能在编写的时候知道这个 ...

  4. TypeScript 素描 - 泛型、枚举

    /* 泛型,好处多多的功能.不过这里最基本的就不打算说了,仅准备说一些 和C#不同的地方 */ /* 泛型接口 GenericIdentityFn 定义了方法的描述等 identity方法则是它的实现 ...

  5. TypeScript Interface(接口)

    类型检查专注于解析值所具有的"形态",这是TypeScript的核心原则之一.这个有时候被称为"duck typing"或者"structural s ...

  6. TypeScript 素描 - 模块解析、声明合并

    模块解析 模块解析有两种方式 相对方式  也就是以/或 ./或-/开头的,比如import jq  from "/jq" 非相对方式  比如 import model  from ...

  7. TypeScript入门-接口

    ▓▓▓▓▓▓ 大致介绍 在TypeScript里,接口的作用就是为这些类型命名和为你的代码或第三方代码定义契约. ▓▓▓▓▓▓ 接口 例子: function printLabel(labelledO ...

  8. TypeScript 素描 - 类

    本文虽然是学自官方教程而来,但是也融入了自己的理解,而且对官方的例子做了一些修改 /* 类 面向对象编程的一大核心 使用C#.Java进行编程的朋友肯定已经是不能够再熟悉了 TypeScript的类与 ...

  9. TypeScript 素描-变量声明

    博文读自 TypeScript 官方文档而来,不具有学习性,仅是本人学习时记录以供日后翻阅 ,有学习TypeScript的朋友还请去看更为详细的官方文档 /* 变量声明在之前的js中一直是使用var关 ...

随机推荐

  1. 关于python字符串连接的操作

    python字符串连接的N种方式 注:本文转自http://www.cnblogs.com/dream397/p/3925436.html 这是一篇不错的文章 故转 python中有很多字符串连接方式 ...

  2. bootstrap表格分页

    <script src="~/Scripts/jquery.min.js"></script> <script src="~/Scripts ...

  3. MBTiles

    MBTiles Specification MBTiles is a specification for storing tiled map data in SQLite databases for ...

  4. python进行mp3格式判断

    python进行mp3格式判断 项目中使用mp3格式进行音效播放,遇到一个mp3文件在程序中死活播不出声音,最后发现它是wav格式的文件,却以mp3结尾.要对资源进行mp3格式判断,那么如何判断呢,用 ...

  5. android AES 加密

    import javax.crypto.Cipher;import javax.crypto.KeyGenerator;import javax.crypto.SecretKey;import jav ...

  6. backup log is terminating abnormally because for write on file failed: 112(error not found)

    昨天遇到一个案例,YourSQLDba做事务日志备份时失败,检查YourSQLDba输出的错误信息如下: <Exec> <ctx>yMaint.backups</ctx& ...

  7. Linux 6.5(oracle 11.2.0.4)单实例ASM安装

    Linux 6.5(oracle 11.2.0.4) 1.解析主机.配置网络等 /etc/hosts /etc/sysconfig/network /etc/init.d/NetworkManager ...

  8. centos7中没有安装ifconfig命令的解决方法

    初装centos 7时,运行config报 command not found 错误,我在网上找了大量资料,下面的资料中查找原因和解决方式最详细,能很好的解决这个问题. ifconfig命令是设置或显 ...

  9. EasyUI combobox

    高度自适应 data-options="required:true,editable:false,panelHeight:'auto',panelMaxHeight:170" 加上 ...

  10. python注释、脚本参数、字节码

    python注释.脚本参数.字节码 --道心 python安装 1.下载安装包 https://www.python.org/downloads/ 2.安装 默认安装路径:C:\python27 3. ...