I am trying to return an array. I read a recordset from SQL and get data:
JavaScript
x
10
10
1
+------------+------------+------------+
2
| start_type | field_name | start_text |
3
+------------+------------+------------+
4
| 0 | Field1 | some text. |
5
+------------+------------+------------+
6
| 0 | Field2 | some more |
7
+------------+------------+------------+
8
| 0 | Field3 | still more |
9
+------------+------------+------------+
10
I want to return this as an array, I try (in a function with Promise<StartText>
):
JavaScript
1
4
1
var results: Array<StartText>=[];
2
results=result.recordset;
3
return results;
4
with StartText:
JavaScript
1
28
28
1
export class StartText {
2
constructor(
3
public startTextId: number,
4
public fieldName: string,
5
public startText: string
6
) {}
7
8
static from(row: {
9
start_text_id: number;
10
field_name: string;
11
start_text: string;
12
}): StartText {
13
return new StartText(
14
row.start_text_id,
15
row.field_name,
16
row.start_text
17
);
18
}
19
20
static toList(result: { recordset: any[] }): StartText[] {
21
const StartTexts: StartText[] = [];
22
result.recordset.forEach((element: any) => {
23
StartTexts.push(StartText.from(element));
24
});
25
return StartTexts;
26
}
27
}
28
but this says:
JavaScript
1
2
1
'StartText[]' is missing the following properties from type 'StartText': startTextId, fieldName, startText.
2
So how do I return the recordset (actually ideally I would like to return a single value for start_type and a dictionary of field_name: start_text pairs but first things first).
Advertisement
Answer
I changed the promise to: Promise <Array<StartText>>
.