Closed chharvey closed 3 years ago
Update:
The Void type is considered “falsy”. If v
is an expression of type void
, then:
!v
is true
(and thus the type of ?v
is true
)v || anything
is the type of anything
v && anything
is void
.Note that this is only for the purposes of type-checking. Since no values can have type void
, the above expressions will all result in compile-time errors.
Type
void
and nullish type operator change.Discussion
The
void
TypeIntroducting a new type: Type
void
represents the absense of a value.void
is unusual in that it doesn’t exactly represent a set of values like the other types do.void
is similar tonever
in that there are no values assignable to it, but there are major differences between the two types. Typenever
is the bottom type, and it represents an expression that never evaluates or a procedure that never executes.never
is the “Identity element of Union”:T | never
is exactlyT
. It’s also the “Absorption element of Intersection”:T & never
is exactlynever
. The bottom type is unique in that it’s a subtype of every other type. On the other hand,void
is a strict supertype ofnever
. Unioning a type with void expressly produces a new type:T | void
is almost always different fromT
. The intersectionT & void
is not particularly useful, but nevertheless it’s not the same asvoid
. Andvoid
is not a subtype of any of the built-in types — it lives amongst the other primitive types such asint
andbool
.void
is also unlikenull
. Typenull
represents a placeholder value that has no prescribed semantics, but it’s still a value nonetheless. Typevoid
has no values assignable to it whatsoever. It represents the completion of an evaluation, but the absence of a value.Breaking: The Nullish Type Operator
The Nullish type operator is shorthand syntax for unioning a type with
null
. In previous versions, this postfix unary operator used the punctuator!
(U+0021 EXCLAMATION MARK). From now on, the punctuator?
(U+003F QUESTION MARK) is the designated symbol. The exclamation mark is now a semantic error, but is still reserved for a different type operation (see #69). This is a breaking change.Specification
Lexicon
Syntax
Semantics
Decorate
Assess
Checklist
?
for nullish type operator & throw TypeError for!
void
keyword to lexer & parser grammars