Skip to content

Instantly share code, notes, and snippets.

@t3dotgg
t3dotgg / try-catch.ts
Last active April 24, 2025 13:01
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@mostafa-hz
mostafa-hz / generate-pagination-query.js
Last active May 27, 2023 18:57
A function to generate keyset paginated queries for mongodb
function generatePaginationQuery(query, sort, nextKey) {
const sortField = sort == null ? null : sort[0];
function nextKeyFn(items) {
if (items.length === 0) {
return null;
}
const item = items[items.length - 1];