let arra: number[] = [100, 200, 300, 400];
let arrb: Array<number> = [500, 600, 700, 800]
let [one, two, three, four] = arra;
let [o] = arrb;
let [, t] = arrb;
let [, , , f] = arrb;
console.log(one, two, three, four, '======123');
console.log(o, '第一位', t, '第二位', f, '第四位')
let obja: any = {
namea: 'zs',
age: 18,
sex: '女'
};
let { namea, age, sex } = obja;
console.log(namea, age, sex, '==========')
interface objb {
nameb: string,
ageb: number,
sexb: string
}
let objb: objb = {
nameb: 'ls',
ageb: 19,
sexb: 'nan'
}
let { nameb, sexb } = objb;
console.log(nameb, sexb, '=========')
interface objc {
namec: string,
agec: number,
sexc: string
}
let objc: objc = {
namec: 'lis',
agec: 19,
sexc: '女'
}
let { namec: c1, agec: c2, sexc: c3 } = objc
console.log(c1, c2, c3, '==========123')
let c11: string;
let c22: number;
let c33: string;
({ c11, c22, c33 } = {
c11: 'lis',
c22: 19,
c33: '女'
})
console.log(c11, c22, c33)
let [a, aa = 20] = [10];
console.log(a, aa)
let ja, jb
({ ja, jb } = { ja: 'aa', jb: undefined })
console.log(ja, jb, '============')
let { one: _one = '哈哈', two: _two = 'xx' } = { one: '我是one' }
console.log(_one, _two, '====')
function x([first, second]: [number, number]): void {
console.log(first);
console.log(second);
}
x([1, 2])
function cc({ color, age = 33 }: { color: string, age?: number }): void {
console.log('color的值:' + color, "age的值为:" + age)
}
cc({ color: 'aaa', age: 20 })
cc({ color: 'red' })
let [a1, b1, ...c] = [1, 2, 3, 4, 8]
console.log(a1, b1, c)
let oo = { texta: '我是a', textb: '我是b', textc: '我是c' }
let { texta, ...passthrough } = oo
console.log(texta, passthrough, '333333333333')
let onee: number[] = [1, 2]
let toww: number[] = [3, 4]
let threed: (number | string)[] = [0, ...onee, ...toww, 5]
console.log(onee, toww, threed)
interface defaultobj {
name: string,
age: number,
color: string
}
let defaultobj: defaultobj = {
name: 'zs',
age: 18,
color: 'yellow'
}
interface targetboj1 {
name: string,
age: number,
color: string,
des: string
}
let targetobj: targetboj1 = {
...defaultobj,
des: '描叙',
name: 'xx'
}
function addd(x: number, y: number): number {
return x + y
}
let result = addd(2, 3)
console.log(result, addd(2, 3))
let sume = (a: number, b: number, callback: (result: number) => void): void => {
callback(a + b)
}
sume(100, 200, (result: number): void => {
console.log('result=' + result)
})
namespace wenDem {
let a: string = '命名空间wenDemo中的变量a'
interface PersonInterface {
name: string,
getInfo()
}
export class Person implements PersonInterface {
name: string;
constructor({ name }) {
this.name = name
}
getInfo() {
return "姓名:" + this.name
}
}
}
let pp = new wenDem.Person({ name: 'xxx' })
console.log(pp.getInfo(), '====123')