Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

typescript

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?

like image 646
RKS_Code Avatar asked Oct 15 '25 17:10

RKS_Code


2 Answers

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.

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 .

like image 24
B0dz1o Avatar answered Oct 17 '25 11:10

B0dz1o