TypeScript: Compiler warnings / errors for common automatic semi-colon insertion (ASI) issues

Personally, I like the look (and simplicity) of ECMA6 / TypeScript without semi-colons. The only problem is that there are some known danger-zones with automatic semi-colon insertion. Could we have compiler warnings to prevent these from slipping through the cracks?

Example:

function dangerous(): string {
    return
        "watch the semi-colons!"
}
dangerous()

Compiles to the following with no warnings or compiler errors (even though the function actually doesn’t return a string):

function dangerous() {
    return;
    "watch the semi-colons!";
}
dangerous();

This specific case is kind of scary / annoying, but it might be worth looking into others.

Thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 28 (12 by maintainers)

Most upvoted comments

+1

another scary example:

var foo = true
// some comment
['a', 'b'].forEach((l: string) => {/**/})

compiles into

var foo = true['a', 'b'].forEach(function (l) {/**/})