Omor Faruk
Omor Faruk

Reputation: 67

How can I assign a type to an array of objects?

The Error is: Type '{ id: string; title: string; content: string; }[]' is missing the following properties from type 'InitialState': id, title, contentts(2739)

interface InitialState {
    id: string,
    title: string,
    content: string
    
}

const initialState:InitialState = [
   {id: '1', title: 'post title', content: 'the fack content'},
   {id: '1', title: 'post title', content: 'the fack content'},
]

Upvotes: 0

Views: 79

Answers (1)

tony.ganchev
tony.ganchev

Reputation: 616

Type of initialState is defined as InitialState but an array is passed instead. switch the type to be InitialState[].

Upvotes: 1

Related Questions