Skip to content

Fails to compile "x = 2 as number" when "as" starts a new line. #24284

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);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions