typesctipt
基础静态类型和对象静态类型
let myage: number = 24
let myname: string = 'fly'
const xiaojiejie1: {
name: string,
age: number,
sex: string
} = {
name: '慕容兰洛',
age: 18,
sex: '女'
}
const xiaojiejies: string[] = ['洛璃', '应欢欢', '绫清竹']
console.log('xiaojiejies', xiaojiejies);
class Person { }
const ren: Person = new Person()
const nihaoxiaojiejie: () => string = () => { return '洛璃' }
console.log('nihaoxiaojiejie', nihaoxiaojiejie);
类型注解和类型推断
const one = 1
const two = 2
const three = one + two
函数参数和返回值的注解
function jisuan(a: number, b: number): number {
return a + b
}
let result = jisuan(1, 2)
function test1(): void {
console.log('22222')
}
function errorFunction(): never {
throw new Error()
console.log('出错了')
}
function forNever(): never {
while (true) { }
console.log('出错了')
}
function getNumber({ one, two }: { one: number, two: number }) {
return one + two
}
let res1 = getNumber({ one: 100, two: 20 })