Good day. I\'m new to Type Script, using VSCode.
Getting following errors:
error TS2322: Type \'() => string\' is not assignable to type
you just use variable type any and remove these types of problem.
error code :
let accessToken = res;
localStorage.setItem(LocalStorageConstants.TOKEN_KEY, accessToken);
given error Argument of type '{}' is not assignable to parameter of type 'string'.
success Code :
var accessToken:any = res;
localStorage.setItem(LocalStorageConstants.TOKEN_KEY, accessToken);
we create var type variable then use variable type any and resolve this issue.
any = handle any type of value so that remove error.
I'm doing angular 2 and typescript and I didn't realize I had a space in my arrow notation
I had .map(key = >
instead of .map(key =>
Definitely keep your eyes open for stupid syntax errors
I was getting this one on this case
...
.then((error: any, response: any) => {
console.info('document error: ', error);
console.info('documenr response: ', response);
return new MyModel();
})
...
on this case making parameters optional would make ts stop complaining
.then((error?: any, response?: any) => {
For what it worth, if anyone has this problem only in VSCode, just restart VSCode and it should fix it. Sometimes, Intellisense seems to mess up with imports or types.
Related to Typescript: Argument of type 'RegExpMatchArray' is not assignable to parameter of type 'string'
In my case, it was that I had a custom interface called Item, but I imported accidentally because of the auto-completion, the angular Item class. Be sure that you're importing from the right package.
This problem basically comes when your compiler gets failed to understand the difference between cast operator of the type string to Number.
you can use the Number object and pass your value to get the appropriate results for it by using Number(<<<<...Variable_Name......>>>>)