0

When I upgrade from angular 8 to angular 9, I am getting a wired error saying that "Type 'string[]' is not assignable to type 'string'." when I run "npm install", below is the code that is getting this error.

let A = "";
if(error instanceof HttpErrorResponse){
...
}else{
  B.fromError(error).then(errors => {
        A = errors.splice(0, 5).map(function(re) {
            return res.toString();
          });
  console.log(A);
}
1
  • 1
    A is of type string because that's what you initialise it as. Later on you're trying to assign an array of strings to it. That's where the type conflict comes from. Commented Aug 31, 2020 at 20:55

2 Answers 2

1

It sounds odd to declare variable A as a string (initializing it to an empty string) and later in the else statement, you're assigning it a string array.

Sign up to request clarification or add additional context in comments.

Comments

1

On the first line you declare A as an empty string:

let A = "";

Then you try to assign A the value of errors, which is an Array

A = errors.splice(0, 5).map(function(re) {
  return res.toString();
});

You can't do that. Maybe replace the first line with:

let A: any[] = [];

Or replace any with whatever type the elements of errors are supposed to be.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.