sortTasks()
function sortTasks(
tasks: readonly {
addedAt: Date | null;
addedByUid: string | null;
assignedByUid: string | null;
checked: boolean;
childOrder: number;
completedAt: Date | null;
content: string;
dayOrder: number;
deadline: | {
date: string;
lang: string;
}
| null;
description: string;
due: | {
date: string;
datetime?: string | null;
isRecurring: boolean;
lang?: string | null;
string: string;
timezone?: string | null;
}
| null;
duration: | {
amount: number;
unit: "minute" | "day";
}
| null;
id: string;
isCollapsed: boolean;
isDeleted: boolean;
isUncompletable: boolean;
labels: string[];
parentId: string | null;
priority: number;
projectId: string;
responsibleUid: string | null;
sectionId: string | null;
updatedAt: Date | null;
url: string;
userId: string;
}[],
options: TaskSortOptions,
context?: TaskSortContext): {
addedAt: Date | null;
addedByUid: string | null;
assignedByUid: string | null;
checked: boolean;
childOrder: number;
completedAt: Date | null;
content: string;
dayOrder: number;
deadline: | {
date: string;
lang: string;
}
| null;
description: string;
due: | {
date: string;
datetime?: string | null;
isRecurring: boolean;
lang?: string | null;
string: string;
timezone?: string | null;
}
| null;
duration: | {
amount: number;
unit: "minute" | "day";
}
| null;
id: string;
isCollapsed: boolean;
isDeleted: boolean;
isUncompletable: boolean;
labels: string[];
parentId: string | null;
priority: number;
projectId: string;
responsibleUid: string | null;
sectionId: string | null;
updatedAt: Date | null;
url: string;
userId: string;
}[];
Sorts the supplied tasks using Todoist view-ordering rules.
The function performs no I/O and always returns a new array. Exact project, workspace, assignee, localized text, and due-time ordering requires the corresponding context. Callers must sort each independent view section or group separately and preserve any subtask structure they render.
This function sorts only the tasks supplied to it. Fetch every page first when globally correct ordering is required for a paginated query.
Parameters
| Parameter | Type |
|---|---|
tasks | readonly { addedAt: Date | null; addedByUid: string | null; assignedByUid: string | null; checked: boolean; childOrder: number; completedAt: Date | null; content: string; dayOrder: number; deadline: | { date: string; lang: string; } | null; description: string; due: | { date: string; datetime?: string | null; isRecurring: boolean; lang?: string | null; string: string; timezone?: string | null; } | null; duration: | { amount: number; unit: "minute" | "day"; } | null; id: string; isCollapsed: boolean; isDeleted: boolean; isUncompletable: boolean; labels: string[]; parentId: string | null; priority: number; projectId: string; responsibleUid: string | null; sectionId: string | null; updatedAt: Date | null; url: string; userId: string; }[] |
options | TaskSortOptions |
context | TaskSortContext |
Returns
{
addedAt: Date | null;
addedByUid: string | null;
assignedByUid: string | null;
checked: boolean;
childOrder: number;
completedAt: Date | null;
content: string;
dayOrder: number;
deadline: | {
date: string;
lang: string;
}
| null;
description: string;
due: | {
date: string;
datetime?: string | null;
isRecurring: boolean;
lang?: string | null;
string: string;
timezone?: string | null;
}
| null;
duration: | {
amount: number;
unit: "minute" | "day";
}
| null;
id: string;
isCollapsed: boolean;
isDeleted: boolean;
isUncompletable: boolean;
labels: string[];
parentId: string | null;
priority: number;
projectId: string;
responsibleUid: string | null;
sectionId: string | null;
updatedAt: Date | null;
url: string;
userId: string;
}[]