I'm getting this issue after upgrading angular version to the latest in my project:
The type 'string' is not assignable to type 'ReportTeamFilter[]'
the problem is when I do searchOptions.BusinessLst = this.business.value;
business = new FormControl('');
var searchOptions: DelegateSearch = new DelegateSearch();
searchOptions.BusinessLst = this.business.value;
delegate.ts
import { ReportingFilter }
export class DelegateSearch {
public BusinessLst: ReportingTeamFilter[];
constructor() {}
}
reporting-model.ts
export class ReportingTeamFilter {
public Id: number;
public Name: string;
public Date: Date;
constructor(){}
}
Any idea on how to fix this issue?
Thank you
CodePudding user response:
I am pretty sure that angular's new typed form feature is responsible for the error produced. Nevertheless the feature probably did not work before during runtime, so I assume it's a good thing that the error is now thrown during development phase.
The error is the following:
- Your are defining
business = new FormControl('');
, which means thatthis.business.value
will return astring
(before typed forms it would returnany
). - Here you are declaring BusinessLst as a different type:
public BusinessLst: ReportingTeamFilter[];
- Now you are trying to assign the string to this array type here
searchOptions.BusinessLst = this.business.value;
That's why the error is thrown. The types simply do not match. You should specify what the correct types are and your error should be gone. Unfortunately I am not able to help you with that, since I do not know the business logic behind these types.
CodePudding user response:
You are expecting array of ReportingTeamFilter and instead of that you are receiving string.
Change BusinessLst to be type string
// From:
public BusinessLst: ReportingTeamFilter[];
// To:
public BusinessLst: string[];