Why forcing a semicolon before the closing bracket of an interface?

Topics: Language Specification
Oct 1, 2012 at 8:51 PM

It seems

interface T { a: string }

doesn't compile because there lacks a comma at the end of the line. JS allows such omissions in many other place so it would be great if I could get the same here?

In fact, I would not force semicolons at all: if I use a linebreak, this is a sufficient sign I declare another field. This just required a [noLineBreak] token in your parser, I think.

Oct 4, 2012 at 5:50 AM

Thanks for the suggestion.  We are discussing this internally as a possible allowance, as it is quite a common mistake (I still do it frequently myself).  Thanks for raising!

Oct 4, 2012 at 9:05 AM

Without dredging up The Great Semicolon Debate of Spring of '12, is there any practical reason why ASI wouldn't work in TypeScript? Or is it a purely stylistic decision to make it look more like C#? I'm okay with either (and personally, I always use semicolons because I'm so used to them).

 

Actually, the case of interfaces is interesting, since without the semicolon, as in @FremyCompany's example, the block looks like an object literal.

Developer
Oct 4, 2012 at 11:57 AM

This is actually just a bug. The spec already permits the last semicolon to be omitted.