Arrays prior to 7.1.0 are stored correctly. In versions later than 7.1 each element is nested in an own array:
class Example {
@prop()
public arrayExample!: string[]
}
const arrayExample: ["1","2","3"]
new Example({arrayExample}).save()
My expectations in DB are:
{
_id: ...,
arrayExample: ["1","2","3"]
}
Its instead:
{
_id: ...,
arrayExample: [["1"],["2"],["3"]]
}
no
class Something {
@prop({ items: String })
public languages?: string[];
}
Note the items:String.
Scott
as @smolinari already said, items: the.actual.type (or now type: the.actual.type) is still needed, it was already needed prior to 7.1
Edit: for an more in-depth explanation on why: https://github.com/microsoft/TypeScript/issues/7169
updated title to better reflect what this issue is (because of duplicates)
The "items" property is now deprecated what would be the correct way to fix this now? When I set type to [String] I get Error: "Example.arrayExample"'s Type is invalid! Type is: "function String() { [native code] }" [E009]. I am only able to fix this by setting type to Schema.Types.Mixed.
@henhen724 please give an example on how you try to set it
(btw, did you try to do type: [String]? when yes, this is only available since 7.4.0)
Yes I did use type: [String], but I am using 7.3.5 so it should work. Here is a repo with a minimal reproducible example: https://github.com/henhen724/typegoose-issue-example. Both the dev and start will throw the error I'm talking about.
like i said in my earlier comment
did you try to do type: [String]? when yes, this is only available since 7.4.0
this syntax is only available since 7.4.0
Sorry, I missed read that
Most helpful comment
Note the
items:String.Scott