I prefer coding style without semicolons. The following snippet gives me an error:
let x = 123
(window as any).test = 'hello'
The error is:
Cannot invoke an expression whose type lacks a call signature. Type 'Number' has no compatible call signatures.
If I put a semicolon at the end of the first line it compiles without an error.
I thought that a newline character should be enough for TS to parse those statements separately. Maybe I don't know something, maybe it's a bug? I'd like to know the explanation, please.
EDIT: In the accepted answer from the provided link it's stated that ASI occurs in case of var
statement. Which makes me think that the same applies to let
and const
.
So, we have a var
statement and a LineTerminator
and according to this TS should parse these two lines as two statements, not one. Where am I wrong?