联合类型
let numStr: number | string = '101-888545213'
const fn = function (type: number | boolean): boolean {
return !!type
}
let a = fn(false)
console.log(a)
交叉类型
interface apple {
name: string
age: number
}
interface da {
gender: number
}
const daBai = (bai: apple & da): void => {
console.log(bai)
}
daBai({
name: '原神小白',
age: 2,
gender: 1
})
类型断言
let ad = function (num: number | string): void {
console.log((num as string).length);
}
ad(123252)
interface A {
uni: string
}
interface B {
bui: string
}
const pdd = (type: A | B): string => {
console.log((<A>type).uni)
}
pdd({
bui:"12334"
})
window.qwe = 894
(window as any).abc = 454