解构
let input=[1,2]
let first=1,second=2;
[first,second]=[second,first]
function f([f,s]:[number,number]) {}
f([1,2])
let [ff, ...ss]=[1,2,3,4]
let [fff]=[1,2,3]
let [,sss,]=[1,2,3]
let ty:[number,string]=[1,'test']
let [a1,b1]=ty
let obj={
a11:'f',
b11:2,
c11:23
}
let {a11,...cc1}=obj
function nn(obj:{a:string,b?:number}) {
let {a,b=11}=obj
}
type C={a:string,b?:number}
function f1({a,b}:C):void {}
扩展
let ffs=[1,2]
let blue=[11,...ffs]
let objb={a:1,b:2}
let objc={...objb,c:22}
接口
interface labelI{
label:string
}
let iob={
label:'ss'
}
function ttt(iob:labelI) {}
interface Point{
readonly x:number;
readonly y:number;
}
let p11:Point={x:10,y:20}
interface Squa{
color?:string;
width?:number;
}
function createSqua(config:Squa):{color:string;area:number} {
return {
color:'str',
area:12
}
}
interface SearchFunc {
(source:string,substring:string):boolean
}
let mySearch:SearchFunc = function(src, sub){
return true
}
interface StringArray{
[index:number]:string;
}
let myarr:StringArray;
myarr=["test","test2"]
let my:string=myarr[0]
类类型
interface ClockInterface{
currentTime:Date;
setTime(d:Date):void;
}
class Clock implements ClockInterface{
currentTime:Date = new Date()
constructor(h:number,m:number) {}
setTime(d:Date){
this.currentTime=d;
}
}