如何使这两个类型定义完全相同?

How to make these two type definitions exactly the same?

我想知道是否有另一种方法来编写 maybe 类型。

type Error = ?{name: string, message:string}
type Error = {name: string, message:string} | null

上面的内容不一样,因为 undefined 情况在第二个定义中是不允许的,但它在第一个定义中。 (source)

然而,下面的方法不起作用。

type Error = {name: string, message:string} | null | undefined

是否有另一种不使用 ? 前缀来表示可能类型的方法?

这有效!

type Error2 = {name: string, message:string} | null | typeof undefined

在 Flow 中 undefined 的类型是 void,所以:

type Error = {name: string, message:string} | null | void

Docs