Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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()">

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 :

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;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading