Closed xiaoqufengdi closed 6 months ago
大神,类型断言那一章,联合类型断言 const s1:number|string = 'hello'; const s2:number = s1 as number; // 报错
const s1:number|string = 'hello'; const s2:number = s1 as number; // 报错
值实际是字符串断言成number会报错, 应该断言成字符串,或者用unkonwn中转一下断言成number const s2:string= s1 as string; const s22: number = s1 as unknown as number
const s2:string= s1 as string; const s22: number = s1 as unknown as number
谢谢指出,已经改正
大神,类型断言那一章,联合类型断言
const s1:number|string = 'hello'; const s2:number = s1 as number; // 报错
值实际是字符串断言成number会报错, 应该断言成字符串,或者用unkonwn中转一下断言成number
const s2:string= s1 as string; const s22: number = s1 as unknown as number