devit2017
devit2017

Reputation: 317

Error TS1005: ':' expected when attempting to instantiate interface

I can not instantiate an interface in Typescript. I created an Interface, but afterward I can not instantiate it.

Code TS:

interface Info {
    name:string;
    age:number;
}

var myInfo: Info ={"med",25}; 

I have get error when compiling:

error TS1005: ':' expected.

Upvotes: 0

Views: 123

Answers (1)

jcalz
jcalz

Reputation: 328152

Your myInfo is not a proper object. You need to specify keys:

var myInfo: Info = { name: "med", age: 25 }; 

Hope that helps you.

Upvotes: 1

Related Questions