简体   繁体   中英

What does the | (pipe) mean at the start of a type in TypeScript

interface MyInterface {     
    someConst:
    | {
        fullName: string
        email: string
      }
    | null
    | undefined
}

My tslint (my linter) added the first | here for me.

I know that the second and third | are a union type but what does the first | do here?

这基本上是 tslint 使代码更易于阅读,它对类型无关紧要,应该被忽略,应该有一个 tslint 规则可以调整 - 如果我可以访问它,也许我可以提供帮助。

Its optional, it doesnt do anything at all. If you send me your tslint, I might give it a look and try to find the rule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM