Skip to content

类型断言 #100

Closed
Closed
@xiaoqufengdi

Description

@xiaoqufengdi

大神,类型断言那一章,联合类型断言
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions