Home:ALL Converter>Typescript Interface to define type for my model

Typescript Interface to define type for my model

Ask Time:2016-01-30T13:46:37         Author:Ant's

Json Formatter

I'm new to typescript and I have interface in typescript like this:

interface Model{
   class : String,
   id: Number
}

and in my model class, I have used this interface like this:

class MyModel{

    model: Array<Model> = []

    pushData(val){
       model.push(val) //error happens here
    }

}

On compilation typescript seems to be throwing error:

error TS2345: Argument of type '{}' is not assignable to parameter of type 'Model'.
  Property 'class' is missing in type '{}'.

I have checked the value of val is nothing but:

{
  class : "test", id : 123
}

which is matching my interface, then why typescript throws this error?

Typescript version is 1.6.2

Author:Ant's,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35098489/typescript-interface-to-define-type-for-my-model
yy