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 lik
There is no real way to achieve what you want. If your only goal is to compress everything onto one line, you can do the following:
public AcccountNumber: number;public branchCode:number;
…but I wouldn't recommend it.
let [string1, string2]: string[] = [];
breaking it down:
[string1, string2]
is declared as string[]
, implying string1, string2
is of type string
[]
[undefined, undefined, undefined, ...]
when destructuring string1
and string2
gets assigned to undefined
string1, string2
are of type string
with value undefined
let notes: string = '', signatureTypeName = '';
If you can accept an orphan variable. Array destructuring can do this.
var numberArray:number[]; //orphan variable
var [n1,n2,n3,n4] = numberArray;
n1=123; //n1 is number
n1="123"; //typescript compile error
Update: Here is the Javascript code generated, when targeting ECMAScript 6.
var numberArray; //orphan variable
var [n1, n2, n3, n4] = numberArray;
n1 = 123; //n1 is number
JS Code generated when targeting ECMAScript 5, like Louis said below, it's not pretty.
var numberArray; //orphan variable
var n1 = numberArray[0], n2 = numberArray[1], n3 = numberArray[2], n4 = numberArray[3];
n1 = 123; //n1 is number
e.g. let isFormSaved, isFormSubmitted, loading: boolean = false; this syntax only works in function block, but not outside of it in typescript export class file. Not sure why is that.
For Example:
export class SyntaxTest {
public method1() {
e.g. let isFormSaved, isFormSubmitted, loading: boolean = false;
}
}