[英]flow: Simpler way to annotate `type | typeof undefined`?
我經常遇到與流有關的同一問題:我將某些內容注釋為?type
並忘記了它接受null
因此當我執行以下操作時:
function foo(data: string = '') {}
function bar(data: ?string) { foo(data); }
flow對我大喊,因為foo(null)
不能將data
解析為string
,但是foo(undefined)
可以。 有沒有更簡單的方法來編寫此代碼:
function bar(data: string|typeof undefined) {
還是我做的事情根本上是錯的?
typeof undefined
void
。
那么呢:
function bar(data: string | void | null) {
要么
function bar(data?: string | null) {
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.