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
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.
The text was updated successfully, but these errors were encountered:
Thanks for the pointer, but the discussion in this ticket seems a bit... inconclusive to me? The other ticket is closed, but I can't see clearly what the upshot of the discussion was (without having read the entire thing).
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 benull
. So, for example to create a nullable (and undefineable) number member...It is currently possible to use a shortcut for
undefined
: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:
... where
number?
is the shorthand fornumber | 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.The text was updated successfully, but these errors were encountered: