Declaring multiple TypeScript variables with the same type

MatthewScarpino picture MatthewScarpino · Dec 11, 2015 · Viewed 59.4k times · Source

I'm coding a large TypeScript class and I've set noImplicitAny to true. Is there any way to declare multiple variables of the same type on the same line?

I'd like to declare x and y as numbers with something like "x, y: number". But the compiler doesn't like that or anything else I've tried. Is there a better alternative to "x: number; y: number"?

Answer

Ryan Cavanaugh picture Ryan Cavanaugh · Dec 11, 2015

There isn't any syntax that would accomplish this in a better way than just writing the type twice.