// 联合类型
// let phone:number | string = 1548546215
// let fn = function (type:number | boolean):boolean{
// return !!type
// }
//
// let result = fn(1)
// console.log(result,'result')
//交叉类型
// interface Pople {
// name: string
// age: number
// }
//
// interface Man {
// sex: number
// }
//
// const heming = (man: Pople & Man): void => {
// console.log(man,'man)
// }
//
// heming({name: "heming", age: 18, sex: 1})
// 类型断言
// 类型断言只能欺骗这个编辑器 无法避免运行时的错误,
// let fn = function (num:number | string):void {
// console.log((num as string).length,'num')
// }
// fn(123456)
//案例
interface A {
run: string
}
interface B {
build: string
}
let fn = (type: A | B): void => {
// console.log((type as A).run)
console.log((<A>type).run)
}
fn()
const fn1 = (type:any): boolean => {
return type as boolean
}
console.log(fn1(1))
标签:TypeScript,console,string,number,第六章,类型,type,fn,log
From: https://blog.csdn.net/XL984507092/article/details/136817240