Flowtype constantly requiring null checks

前端 未结 2 1580
情书的邮戳
情书的邮戳 2021-02-14 00:52

I\'m wondering how to avoid these numerous null checks or at least understand what the point is because it seems counter-productive.

Flowtype is giving me an error for

2条回答
  •  梦谈多话
    2021-02-14 01:05

    When I know for sure that my variable won't be null and Flow doesn't, I use an unwrap() function:

    export default function unwrap(value: T): $NonMaybeType {
      if (value !== null && value !== undefined) return value
      throw new Error('Unwrapping not possible because the variable is null or undefined!')
    }

提交回复
热议问题