export default class Foo {
first: string;
second: X[];
}
export function parse(foo?) {
if(foo) {
return Builder<Foo>(Foo)
.first(foo.first || "")
.second(XFunctions.parse(foo.second.map(second => XFunctions.parse(second))))
.build();
}
And I'm receiving the error as stated above: "argument of type X is not assignable to parameter of type X[]"
Here is the code for my X class:
export default class X {
first: string;
second: string;
third: string;
fourth: boolean
}
export function parse(x?) {
if(x) {
return Builder<X>(X)
.first(x.first || "")
.second(x.second || "")
.third(x.third || "")
.fourth(x.fourth)
.build();
}
return Builder<X>(X)
.first("")
.second("")
.third("")
.fourth(true)
.build();
}
I thought using map() would do the track as it would iterate over each element in X[], applying the parse function to each, but I must be misunderstanding how this works. I know this error is a common issue, and if another question I haven't seen better answers my question, I apologize in advance.