RKS_Code
RKS_Code

Reputation: 540

Why does typescript not issue an error on missing semicolon at the end of statement

For example, if I use following statements, I see no compiler error.

public SomeFunction() {

    this.privateFunction() (no semi colon here)
}

or

public SomeFunction() {

    this.privateFunction();
}

I am wondering if semicolon at the end of every statement is really required?

Upvotes: 4

Views: 9051

Answers (2)

B0dz1o
B0dz1o

Reputation: 671

Typescript, as a superset of JS, utilises the latter's Automatic Semicolon Insertion. If you want to learn more about where it will be implicitly put, read here -> http://inimino.org/~inimino/blog/javascript_semicolons .

Upvotes: 4

user5004821
user5004821

Reputation:

Semicolons are optional in JavaScript - TypeScript is a superset of JavaScript, ergo, semicolons are optional in TypeScript. That said, you will still run into issues with ASI like you would with JavaScript if you don't know where semicolons will be automatically placed.

Upvotes: 9

Related Questions