Search code examples
typescripttypesvariable-types

Declaring multiple TypeScript variables with the same type


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"?


Solution

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