Description
Static analysis on "nullable" variables is a good thing. However, using this feature also requires to explicitly create union types with null
for every variable and member that can in fact be null
. So, for example to create a nullable (and undefineable) number member...
interface MyInterface {
x: number | null | undefined
}
It is currently possible to use a shortcut for undefined
:
interface MyInterface {
x?: number | null
}
Note that the two interface definitions above are equivalent, but | null
is always required.
However, for my taste, this is all way too verbose for something as common as a nullable type. I would like to propose the following:
interface MyInterface {
x: number?
}
... where number?
is the shorthand for number | null | undefined
. This little tweak would save a lot of typing and improve general acceptance of strict null checking. This isn't a new idea. Languages like Ceylon use the same method and syntax.