deen
deen4w ago

nullThrows has wrong type or jsdoc

/**
* Filters out null elements from an array.
* @param list List of elements that might be null.
* @returns List of elements with nulls removed.
*/
export function pruneNull<T>(list: (T | null)[]): T[] {
return list.filter((i) => i !== null) as T[];
}

export class NullDocumentError extends Error {}

/**
* Throws if there is a null element in the array.
* @param list List of elements that might have a null element.
* @returns Same list of elements with a refined type.
*/
export function nullThrows<T>(doc: T | null, message?: string): T {
if (doc === null) {
throw new NullDocumentError(message ?? "Unexpected null document.");
}
return doc;
}
/**
* Filters out null elements from an array.
* @param list List of elements that might be null.
* @returns List of elements with nulls removed.
*/
export function pruneNull<T>(list: (T | null)[]): T[] {
return list.filter((i) => i !== null) as T[];
}

export class NullDocumentError extends Error {}

/**
* Throws if there is a null element in the array.
* @param list List of elements that might have a null element.
* @returns Same list of elements with a refined type.
*/
export function nullThrows<T>(doc: T | null, message?: string): T {
if (doc === null) {
throw new NullDocumentError(message ?? "Unexpected null document.");
}
return doc;
}
nullThrows checks a single item, despite indicating it works with a list. PS: If anyone dives into the helpers repo, there's a typo in the readme: Sessions: client-generatead
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?