You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support the literal type undefined and distinguish undefined from void.
The proposal may be divided into two proposals:
add undefined type (backward compatible) (done)
make void type the absence of value (breaking change)
Add undefined type
constx: undefined=undefined// ✔️functionf(x: undefined): void{}f()// ❌ parameter is requiredf(undefined)// ✔️functiong(): undefined{/* ❌ return is required */}functionh(): undefined{return/* ❌ a value must be returned */}functionj(): undefined{returnundefined/* ✔️ */}
make void type the absence of value
constx: void// ❌ void cannot be used as variable typefunctionf(x: number|void): void{}functionf(x?: number): void{}// equivalentf()// ✔️f(undefined)// ❌functiong(): void{return undefined /* ❌ */}functiong(): void{ return /* ✔️ */}
Use case / Rationales
This makes Flow more compatible with TypeScript.
This allows to type a function with a required parameter that accepts undefined:
functiong(x: number|undefined){}f()// ❌ parameter is requiredf(undefined)// ✔️
This makes the intent more clear: void is often associated with the absence of value. The use of void to denote undefined is misleading.
The text was updated successfully, but these errors were encountered:
Hi!
Proposal
Support the literal type
undefined
and distinguishundefined
fromvoid
.The proposal may be divided into two proposals:
add(done)undefined
type (backward compatible)void
type the absence of value (breaking change)Add
undefined
typemake
void
type the absence of valueUse case / Rationales
This makes Flow more compatible with TypeScript.
This allows to type a function with a required parameter that accepts
undefined
:This makes the intent more clear:
void
is often associated with the absence of value. The use of void to denoteundefined
is misleading.The text was updated successfully, but these errors were encountered: