Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: typescript v2.9.0-dev.20180519
(Also with v2.8.3)
Search Terms:
"as keyword" newline
"as keyword" whitespace
Code
Fails:
const x = 2
as number;
console.log(x);Works:
const x = 2 as
number;
console.log(x);Expected behavior:
Successful compilation (and output "2"...).
Actual behavior:
tsnode says:
...(2,4): ';' expected. (1005)
Playground puts wiggly red lines on everything, starting on first as.
Playground Link: https://www.typescriptlang.org/play/#src=const%20x%20%3D%202%0D%0A%20%20as%20number%3B%0D%0Aconsole.log(x)%3B%0D%0A
Related Issues:
Couldn't find something similar (see search terms above). It looks related to the general weirdness associated with newlines in JavaScript. The playground seems to support this, it shows this translation:
x = 2;
as;
number;
console.log(x);Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bug
Activity
j-oliveras commentedon May 21, 2018
This is because automatic semicolon insertion, so this is intended. The sample is parsed as:
but because
asandnumberare not expected typescript shows errors (and try to do it's better to parse them).RyanCavanaugh commentedon May 21, 2018
Might be ASI concerns here, but I think we can safely parse an "as " from the next line?
DanielRosenwasser commentedon May 21, 2018
No, this is the intended behavior:
typescript-bot commentedon Jun 6, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.