TS 2322 Type 'null' is not assignable to type 'string'
I have Angular 12 project which has typescript 4.2.3 I'm getting bunch of these errors. In this case, I'm passing appLang parameter to child component.
So here's my html:
<app-bankcard-call-flows [appLang]="getLanguage()">
I'm trying to pull value from the coordinating component:
public getLanguage() {
this.appLang = this.language;
}
I'm getting error:
TS2322: Type 'void' is not assignable to type 'string'.
<app-bankcard-call-flows [appLang]="getLanguage()"></app-bankcard-call-flows>
Solution 1:
The method getLanguage()
does not return anything so you're essentially passing void
to the [appLang]
input while it expects a string.
Either use [appLang]="appLang"
or change the method to return the appLang
:
public getLanguage(): string {
return this.language;
}