1

I am trying to declare:

type ArticleModel = {
    _id: number;
    name: string;
}

Then in my class:

public models: ArticleModel[];

Where models should be as you may have guess an array of ArticleModel.

But node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js throws:

error TS2322: Type 'Object[]' is not assignable to type '{ _id: number; name: string; }[]'.
  Type 'Object' is not assignable to type '{ _id: number; name: string; }'.
    Property 'id' is missing in type 'Object'..

Any help would be appreciated.

Thanks in advance.

1
  • Don't get confused with id and _id, it's just a typo in here... Commented Nov 7, 2017 at 18:26

2 Answers 2

7

Ok my bad, I was re-declaring the variable later as:

let models:Array<Object> = [];

Cheers

Sign up to request clarification or add additional context in comments.

Comments

3

if you want to instantiate your object array when you create your class, you can do this:

public models: ArticleModel[] = [];

This is in place of doing it in the class constructor.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.