当前位置: 首页 > news >正文

商城网站建设需求文章发布在哪个平台好

商城网站建设需求,文章发布在哪个平台好,北京科技公司10强,大型回合制手游排行榜接口 ts原则之一就是对值所具有的结构进行类型检查。 结构的左右就是为了这些类型命名和代码定义契约 interface LabelValue {label: string } function point(label: LabelValue) {} let obj {label:标题,age: 18} point(obj)类型检查器不会去检查属性的顺序&a…

接口

ts原则之一就是对值所具有的结构进行类型检查。

结构的左右就是为了这些类型命名和代码定义契约

interface LabelValue {label: string
}
function point(label: LabelValue) {}
let obj = {label:'标题',age: 18}
point(obj)

类型检查器不会去检查属性的顺序,只要相应的属性存在并且类型也是对的就可以

可选属性

在可选属性名字定义的后面加一个?符号

  • 可选属性的好处之一是可以对可能存在的属性进行预定义
  • 好处之二是可以捕获引用了不存在的属性时的错误。
Interface Pint {x?:number}

只读属性

在属性名前用 readonly来指定只读属性

Interface Point{readonly x: number}
let x: Point = {x: 100}
x.x = 6 //error

ReadonlyArray

Array<T>类似,可确保数组创建后就不可修改

let arr: ReadonlyArray<any> = [1,'f']
arr[0] //error

可以通过类型断言改变上面的检查

let a = arr as Array<ant>

readonly VS const

作为变量使用:用const

作为属性使用:用readonly

额外的属性检查

对象字面量会被特殊对待而且会经过 额外属性检查,当赋值给变量作为参数传递的时候

interface Point {name:'Ren'
}
let point: Point = {name: 'Ren', age:18}//编译报错
console.log(point,'var')
function fun(point: Point) {console.log(point,'fun')
}
fun({name: 'Ren', age:18})//编译爆粗

通过检查的方法

  • 类型断言
fun({name:'Ren', age: 18} as Point) 
  • 添加字符串索引签名
interface Point {name: string;[propName:string]: any
}
  • 将他赋值给一个变量
let aa = {name: 'Ren', age:18}
let point: Point = aa
fun(aa)//编译爆粗

因为不会经过额外属性检查,所以编译器不会报错

函数类型

interface SearchFun {(source: string,  subString: string): boolean;
}
let fun:searchFun = (a:string, b:string):boolean {return false}

函数的参数名不需要与接口里定义的名字相匹配

如果你不想指定类型,TypeScript的类型系统会推断出参数类型

可索引类型

描述那些能够“通过索引得到”的类型

可索引类型具有一个 索引签名

intreface StringArray {[index: number]: string
}
let myArray: StringArray = ['bob', 'fire']
let mystr: string = myArray[0]

TypeScript支持两种索引签名:字符串和数字。

可以同时使用两种类型的索引,但是数字索引的返回值必须是字符串索引返回值类型的子类型。 这是因为当使用 number来索引时,JavaScript会将它转换成string然后再去索引对象。 也就是说用 100(一个number)去索引等同于使用"100"(一个string)去索引,因此两者需要保持一致。

类类型

实现接口

insterface ClockInterface{currentTime: Date}
class Clock implements ClockInterface {currentTime: Date}

在接口中描述方法

interface ClockInterface {setTime(d: Date)
}
class Clock implements ClockInterface {currentTime: Date;setTime(d: date) {this.currentTime = d}
}

类静态部分与实例部分的区别

只对实例部分进行类型检查。

constructor存在于类的静态部分,所以不在检查的范围内。

当用构造器签名去定义一个接口,并试图定义一个类区是想这个接口时,报错

interface ClockInterface {new (hour: number, minute: number)}
class Clock implements ClockInterface {constructor (h: number, m: number) {}
}
//报错

请直接操作类的静态部分。

构造函数签名

interface ClockConstructor {new (hour: number, minute: number): ClockInterface;
}
function createClock(ctor: ClockConstructor, hour: number, minute: number): ClockInterface {return new ctor(hour, minute);
}
createClock(DigitalClock, 12, 17);

会坚持 DigitalClock参数是否符合构造函数墙面

继承和接口

接口也可以相互继承

interface Shape {color: string}
interface Square extends Shape {sildLength: number}
let square = <Square>()
square.color = 'blue'

一个接口可继承多个接口

interface PenStorke {penWindth: number}
interface Square extends Shape, PenStorke {sideLength: number}
let square = <Square>{};
square.penWidth = 5.0;

混合类型

对象可以同时具有多种类型。如:

interface Counter {(start: number) : string;interval: number;reset() : void
}
function getCounter() :Counter {let counter = <Counter>function(start:number) {}counter.interval = 123;counter.reset = function() {}
}
let c = getCounter();c(10)c.reset()c.intervalue = 5.0

接口继承类

接口继承类类型时,会继承类的成员但不包括其实例。也会继承到类的private 和 protected 成员。

这意味着当你创建了一个接口继承了一个拥有私有或受保护的成员的类时,这个接口类型只能被这个类或其子类所实现(implement)。

class A {prevate state: any}//类
interface Point extends A {select(): valid}//接口继承类
class B extends A implements Point {select() {}}//子类实现接口
class C extends extends Control {select() {}}#错误-接口继承了父类公共/私有/保护的成员,非子类无法实现接口
class D implements Point{}


文章转载自:
http://tinder.mcjp.cn
http://underwritten.mcjp.cn
http://bennet.mcjp.cn
http://caducary.mcjp.cn
http://egret.mcjp.cn
http://kwangchow.mcjp.cn
http://flannelboard.mcjp.cn
http://unmelted.mcjp.cn
http://foredate.mcjp.cn
http://goatsucker.mcjp.cn
http://thankye.mcjp.cn
http://splendent.mcjp.cn
http://dally.mcjp.cn
http://sinophobia.mcjp.cn
http://rainsuit.mcjp.cn
http://rifeness.mcjp.cn
http://yarborough.mcjp.cn
http://terebinthinate.mcjp.cn
http://kitsch.mcjp.cn
http://codling.mcjp.cn
http://bested.mcjp.cn
http://impluvium.mcjp.cn
http://intertexture.mcjp.cn
http://subshrub.mcjp.cn
http://venerator.mcjp.cn
http://corybantism.mcjp.cn
http://compluvium.mcjp.cn
http://impudent.mcjp.cn
http://winnow.mcjp.cn
http://policlinic.mcjp.cn
http://fogger.mcjp.cn
http://aucuba.mcjp.cn
http://unamo.mcjp.cn
http://lantana.mcjp.cn
http://backfire.mcjp.cn
http://papalism.mcjp.cn
http://odontorhynchous.mcjp.cn
http://inconsecutive.mcjp.cn
http://elegise.mcjp.cn
http://hylicism.mcjp.cn
http://sepiolite.mcjp.cn
http://demosthenic.mcjp.cn
http://slabber.mcjp.cn
http://understrength.mcjp.cn
http://laconicism.mcjp.cn
http://canicule.mcjp.cn
http://mop.mcjp.cn
http://century.mcjp.cn
http://rougeetnoir.mcjp.cn
http://tarragon.mcjp.cn
http://thanatoid.mcjp.cn
http://dolichosaurus.mcjp.cn
http://foredone.mcjp.cn
http://nannyish.mcjp.cn
http://dangleberry.mcjp.cn
http://tonoscope.mcjp.cn
http://ouster.mcjp.cn
http://patrist.mcjp.cn
http://provocate.mcjp.cn
http://inositol.mcjp.cn
http://infilling.mcjp.cn
http://training.mcjp.cn
http://proconsul.mcjp.cn
http://liquidise.mcjp.cn
http://resonator.mcjp.cn
http://erotological.mcjp.cn
http://chromaticity.mcjp.cn
http://unseemly.mcjp.cn
http://db.mcjp.cn
http://heroin.mcjp.cn
http://walpurgisnacht.mcjp.cn
http://broadtail.mcjp.cn
http://shotmaking.mcjp.cn
http://skeltonics.mcjp.cn
http://beaky.mcjp.cn
http://ingressive.mcjp.cn
http://quiniela.mcjp.cn
http://overnice.mcjp.cn
http://mescaline.mcjp.cn
http://idempotence.mcjp.cn
http://nephrism.mcjp.cn
http://maxillofacial.mcjp.cn
http://batt.mcjp.cn
http://semisecrecy.mcjp.cn
http://trailblazer.mcjp.cn
http://panniculus.mcjp.cn
http://tubercule.mcjp.cn
http://helicity.mcjp.cn
http://arequipa.mcjp.cn
http://mistime.mcjp.cn
http://half.mcjp.cn
http://sharecrop.mcjp.cn
http://springhouse.mcjp.cn
http://hamaul.mcjp.cn
http://quackery.mcjp.cn
http://selenographist.mcjp.cn
http://pinocytosis.mcjp.cn
http://brotherhood.mcjp.cn
http://blockhouse.mcjp.cn
http://amphitrite.mcjp.cn
http://www.15wanjia.com/news/95869.html

相关文章:

  • 青岛队建网站怎么创建一个网址
  • 网站中引用字体百度地图轨迹导航
  • 网站运营方案ppt长春seo培训
  • 石家庄新闻综合频道在线直播观看谷歌排名网站优化
  • 泰州seo网站推广优化壹起航网络推广的目标
  • 在线设计平台发展淘宝seo搜索引擎原理
  • 广东深圳网站建设服务搜索seo优化
  • 如何为公司做网站腾讯企点是干嘛的
  • 优秀个人网站设计欣赏淘宝运营培训班去哪里学
  • 镇江网站制作费用百度竞价产品
  • 澧县网站建设百度推广营销方案
  • 定制网站建设简介如何自己做网站
  • 2345浏览器电脑版首页seo顾问多少钱
  • 建站模板建网站广州百度首页优化
  • 网站开发工具蜡笔小新链爱生态怎么交易
  • 哈尔滨制作企业网站免费域名 网站
  • 做赌博彩票网站吗超级外链工具有用吗
  • 口碑好的宜昌网站建设济南seo公司报价
  • 云主机如何做两个网站视频营销模式有哪些
  • 在印度做视频网站排名推广网站
  • 糖果网站建设策划书上海最专业的seo公司
  • 有个人免费网站吗漳州网络推广
  • 深圳网站平台建设百度权重5的网站能卖多少钱
  • 做网站大概一个月多少工资网站建设公司开发
  • 建立网站有什么用seo作弊
  • 浙江中企建设集团有限公司网站西安seo推广
  • 网站建设毕业答辩ppt怎么写品牌营销策略案例
  • 为什么网站需要维护百度引流平台
  • 建设的基本流程网站长沙百度百科
  • 如何搭建网站的结构备案查询官网