Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Explains advanced TypeScript patterns such as generics with constraints, conditional and mapped types, template literals, and type guards.
Use this skill ↓87% 91%+4 ptsof test cases passed
Passed 21 of 23 test cases with the skill, and 20 of 23 without it.
3 of 3 safety checks passed
Not used yet
interface HasId {
id: string;
}
function findById<T extends HasId>(items: T[], id: string): T | undefined {
return items.find(item => item.id === id);
}
function groupBy<T, K extends string | number>(
items: T[],
keyFn: (item: T) => K
): Record<K, T[]> {
return items.reduce((acc, item) => {
const key = keyFn(item);
(acc[key] ??= []).push(item);
return acc;
}, {} as Record<K, T[]>);
}
type ApiResponse<T> = {
data: T;
meta: { page: number; total: number };
};
async function fetchApi<T>(url: string): Promise<ApiResponse<T>> {
const res = await fetch(url);
return res.json();
}
type IsString<T> = T extends string ? true : false;
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.