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

Typescript interfaces – missing properties

I have these two interfaces:

export interface interface1 {
   id: number;
   name: string;
   description: string;
   isActive: boolean; 
   address?: {};
}
export interface interface2 extends interface1 {
   route: string;
}

When I implement interface2 like this:

const const1: interface2 = [
   id: 1,
   name: 'abc',
   description: 'desc',
   isActive: true,
   route: '/'
]

While compiling I am getting all properties listed as missing. Not sure what I am doing wrong. I checked this playground it seems working fine:
Example

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

>Solution :

It seems that there is a syntax error in the implementation of const1. Instead of using square brackets, you should use curly braces to define an object literal.

const const1: interface2 = { id: 1, name: 'abc', description: 'desc', isActive: true, route: '/' };

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