Reputation: 5904
I've been searching for an answer to this question for a while and am getting mixed messages. I know semicolons are necessary in JavaScript because of the automatic semicolon insertion (ASI), but does TypeScript have the same restriction?
I would assume that it doesn't, since it transpiles down to JavaScript, and most likely inserts a semicolon for you in the places where the ASI would cause a problem. But I would like to know for sure.
Upvotes: 9
Views: 6622
Reputation: 12018
TypeScript follows the same ASI rules as JavaScript. Semicolons are technically not required in either language, save for a few rare, specific cases. It's best to be educated on ASI regardless of your approach.
Notably, ASI also applies inside of interface and object type bodies:
// valid
interface Person {
name: string;
age: number;
}
// also valid
interface Person {
name: string
age: number
}
// not valid
interface Person { name: string age: number }
Upvotes: 14