Good day. I\'m new to Type Script, using VSCode.
Getting following errors:
error TS2322: Type \'() => string\' is not assignable to type
Also adding other Scenarios where you may see these Errors
First Check you compiler version, Download latest Typescript compiler to support ES6 syntaxes
typescript still produces output even with typing errors this doesn't actually block development,
When you see these errors Check for Syntaxes in initialization or when Calling these methods or variables,
Check whether the parameters of the functions are of wrong data Type,you initialized as 'string' and assigning a 'boolean' or 'number'
For Example
1.
private errors: string;
//somewhere in code you assign a boolean value to (string)'errors'
this.errors=true
or
this.error=5
2.
private values: Array<number>;
this.values.push(value); //Argument of type 'X' is not assignable to parameter of type 'X'
The Error message here is because the Square brackets for Array Initialization is missing, It works even without it, but VS Code red alerts.
private values: Array<number> = [];
this.values.push(value);
Note:
Remember that Javascript typecasts according to the value assigned, So typescript notifies them but the code executes even with these errors highlighted in VS Code
Ex:
var a=2;
typeof(a) // "number"
var a='Ignatius';
typeof(a) // "string"
In my case, strangely enough, I was missing the import of the class it was complaining about and my IDE didn't detect it.
You miss parenthesis:
var value: string = dataObjects[i].getValue();
var id: number = dataObjects[i].getId();