Argument of type 'X' is not assignable to parameter of type 'X'

前端 未结 9 2087
名媛妹妹
名媛妹妹 2021-02-02 05:15

Good day. I\'m new to Type Script, using VSCode.

Getting following errors:

  1. error TS2322: Type \'() => string\' is not assignable to type

9条回答
  •  天命终不由人
    2021-02-02 05:29

    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.

提交回复
热议问题