I am trying to concatenate two Strings in typescript as follows:
//This array is declared as a class variable
testArray: String[] = ['first', second', 'third'];
concatArray(): void {
var testString = new String("");
this.testArray.forEach((item, index) => {
testString = testString.concat(item);
});
console.log(testString);
}
When run the console.log will output the correct value: 'firstsecondthird'
However i get a compile error which says:
error TS2345: Argument of type 'String' is not assignable to parameter of type 'string'.
'string' is a primitive, but 'String' is a wrapper object.
Prefer using 'string' when possible.
I don't understand this error as both the testArray and the testString both seem to be of type String?
I'm new to typescript. Could somebody point out what is problem here?