I am trying to assign an Array of Article to my mongoose document, but it seems Typescript doesn't like that and I don't know why it's showing this warning/error that it's not assignable.
My mongoose Schemas and interfaces (simplified):
interface Profile {
username: string,
articles: [Article]
}
interface Article {
index: number,
name: string,
}
// Mongoose model
export interface IProfile extends Profile, Document { }
const Article = new Schema({
index: { type: Number, required: true },
name: { type: String, required: true },
}, { _id: false })
const Profile = new Schema({
username: { type: String, index: true },
upcomingChests: { type: [Article] },
}, { timestamps: true })
export const Profile = model<IProfileModel>('IProfile', Profile)
My code trying to assign Articles:
const profile: Profile = values[0]
const articles: Array<Article> = values[1]
profile.articles = articles // Error/Warning pops up in this line
[ts] Type 'Article[]' is not assignable to type '[Article]'.
Property '0' is missing in type 'Article[]'.
My question:
Why does it say it's not assignable and what's the difference between [Article] and Article[] at all?