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

Nullable boolean in Angular

I’m trying to set a array with a null in to a boolean, but I dont know how to do it, here is my code

export interface PeriodicElement {  
caja: boolean;
tractor: boolean;
}
const ELEMENT_DATA: PeriodicElement[] = [
{caja:null, tractor:false}
]

>Solution :

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

You can use union types to achieve this.

Union Types – Typescript docs

The first way to combine types you might see is a union type. A union type is a type formed from two or more other types, representing values that may be any one of those types. We refer to each of these types as the union’s members.

export interface PeriodicElement {  
   caja: boolean | null;
   tractor: boolean | null;
}
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