Код: Выделить всё
const response = await new Http().apiServer().get(this.endpoint);
Код: Выделить всё
public apiServer(): AxiosInstance {
return axios.create({
baseURL: this.configuration.API_URL,
});
}
< /code>
1 -й JSON API -ответ: < /p>
{
"content": {
"elementsList": [
{
"index": 1,
"segments": [
{
"$type": "typeb",
"someBooleanValue": false,
"someOtherChildComponents": [
{
"index": 1,
"text": "dfasdfasdfsadfsdf",
"anotherArray": [
{
"index": 1,
"text": "maybe"
},
{
"index": 2,
"text": "no"
}
]
}
],
"index": 1,
"title": "dummy title nb 1"
},
{
"$type": "typeb",
"someBooleanValue": true,
"someOtherChildComponents": [
{
"index": 1,
"text": "sfsdfasfsfsfsf",
"anotherArray": [
{
"index": 1,
"text": "fsafasdfsafsdf"
},
{
"index": 2,
"text": "sadfsadfsadfsadfsadfsadfdsa"
},
{
"index": 3,
"text": "sadfsadfasdfdsaf"
}
]
},
{
"index": 2,
"text": "dafdsafasfsdffdfafsffadfadfasdf",
"anotherArray": [
{
"index": 1,
"text": "safsafsadfsaffsa"
},
{
"index": 2,
"text": "sadfsafsadfafsad"
},
{
"index": 3,
"text": "dfasdfsadfasd"
}
]
},
{
"index": 3,
"text": "dfsadfsadfsadfsadf",
"anotherArray": [
{
"index": 1,
"text": "sadfsadfsadfa"
},
{
"index": 2,
"text": "fasfdsadfsadfad"
},
{
"index": 3,
"text": "sadfasdfasfsadf"
},
{
"index": 4,
"text": "fsdfsdfaasdfasfadf"
}
]
}
],
"index": 2,
"title": "dummy title nb 2"
},
{
"$type": "typea",
"htmlContent":
dummy
",
"index": 3,
"title": "dummy title nb 3"
}
]
}
]
},
"status": 0,
"otherValue": 0
}
export type payloadType = {
content: ContentType;
statusType: TStatus;
otherValue: number;
};
export enum SegmentType {
TypeA = 'typea',
TypeB = 'typeb',
}
export interface Segment {
$type: SegmentType;
index: number;
title: string;
}
export interface TypeASegment extends Segment {
$type: SegmentType.TypeA;
htmlContent: string;
};
export interface TypeBSegment extends Segment{
$type: SegmentType.TypeB
someBooleanValue: boolean;
someOtherChildComponents: OtherChildComponentType[];
};
< /code>
Проблема заключается в том, что я регистрирую ответ запроса GET: < /p>
Когда я вызываю конечную точку, которая возвращает 1 -й ответ JSON Все атрибуты типа $ - это «типоя». Последний один тип что я использую в типахрегменте
Я также заметил, что типы все еще влияют на картирование, даже если я не делаю никакого типа или объявления типа, который мне нужен.
Подробнее здесь: https://stackoverflow.com/questions/794 ... -correctly
Мобильная версия