Literals cannot be different types. Typescript infers a union type from all array elements in literal (you can see it in the error message). You can define all
above options
as Record<string, any>[]
:
const all: Record<string, any>[] = [
{ datetimestart: {from: currentDateTimeInISOString}},
{ price: {from: 0, to: (freeEventsOnly ? 0.1 : 99999999999) }},
]
const jsonData = {
query: "keywords in here",
page: {size: 10, current: 1},
options: {
all,
},
};
if (meetSomeCondition) {
jsonData.options.all.push({ city: domicile }); // <--- try to append another object to array
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…