Open 747 opened 11 months ago
soso: number = 0
has a non-declaration meaning (object literal with an assignment in the value). I hesitate to change its behavior in autoLet
mode. Rather, the intent is that manual let
s should use .=
syntax as usual. autoLet
affects assignments, and soso: number = 0
isn't a valid assignment of soso
(rather, it's an assignment to number
).
I would suggest allowing syntax like below if it wouldn't cause other semantic conflicts. It feels more mentally consistent (at least inside me) when someone is using autoLet
(or autoVar
).
x(: number) = 0
Would it be possible to do something here with the new ::
operator?
Yes, interesting idea: we could define sos:: number = 5
to mean sos = 5
and give the type annotation number
to autoLet
/autoVar
. (This feels similar to my old CoffeeScript fork that used sos ~ number = 5
.)
I guess sos:: number = 5
is slightly easier to type than sos: number .= 5
, and probably nicer in an autoLet
/autoConst
(e.g. CoffeeScript) codebase that otherwise only uses =
for declaration. But it is also very close...
I will point out that it's a different meaning than we currently have for ::
, which can only occur in declarations and only within items of array and object patterns. Currently the declaration sos:: number .= 0
isn't valid (though it could be), and even less so with assignment (=
). But we can decide what ::
means in a broader context.
Without
autoLet
:generates
but under
autoLet
:to be
(the comment behaves weirdly as well, but it is not in the scope of this discussion :P)