Skip to content
tezvyn:

All bites

The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.

8668 bites

Page 117

TypeScript & Web APIs2 min read

Write a generic PickByValue<T, V> type

Tests conditional types and mapped-type key remapping. Great answer: K in keyof T as T[K] extends V ? K : never with value T[K]. Red flag: writing V extends T[K] instead, which reverses the assignability check and includes wrong keys.

TypeScript & Web APIs2 min read

Implement the built-in NonNullable<T> utility type from scratch

Tests conditional type distribution and union filtering. A strong answer uses distributive conditional types to map null and undefined to never while preserving other union members.

TypeScript & Web APIs2 min read

Implement MyParameters<T> using conditional types and infer

Tests if you can extract parameter types with infer. A strong answer matches T against a callable signature, uses infer to bind parameters into a tuple, and defaults to never for non-functions. Red flag: using any or indexing without inference.

TypeScript & Web APIs2 min read

Create TerminalStatus from Status using Exclude or Extract

This tests conditional type mechanics and whitelist versus blacklist thinking. Extract selects matches by assignability; Exclude removes others. Prefer Extract when the desired set is explicit. Red flag: claiming they are equivalent or only knowing Exclude.

TypeScript & Web APIs2 min read

Write a generic MakeOptional<T> mapped type without using Partial

This tests mapped type mechanics and the optionality modifier. A strong answer iterates over keyof T, adds the ? modifier, and preserves the original type via indexed access. A red flag is suggesting Object.assign or saying you would just use Partial.

TypeScript & Web APIs2 min read

Create a User type alias from a function return type

Use typeof to grab the function type, then ReturnType to extract the return object shape.

TypeScript & Web APIs2 min read

Describe a common use for Partial<T> and explain Required<T>

Partial fits PATCH updates where only some fields arrive; Required strips optionality to enforce all properties.

TypeScript & Web APIs2 min read

Explain Pick versus Omit with User examples

Pick keeps listed keys; Omit drops them. Show User with id, name, email; derive Pick<User,"name"|"email"> and Omit<User,"id">.

TypeScript & Web APIs2 min read

Implement a generic PickByType<T, U> utility type

Tests mapped-type key filtering via conditional types and as remapping. Great answer: [K in keyof T as T[K] extends U ? K : never]: T[K]. Red flag: mapping all keys and setting values to never, which preserves keys instead of removing them.

TypeScript & Web APIs2 min read

Implement MyReturnType<T> using conditional types and infer

This tests type-level pattern matching with conditional types and infer. Answer uses T extends (...args: any[]) => infer R ? R : never, noting infer captures return slot, non-functions yield never. Red flag: conflating runtime values with compile-time types.

TypeScript & Web APIs2 min read

Write a generic fetchJSON<T> wrapper and explain its type safety benefits

Tests preserving type info across async boundaries via generics. Outline: write fetchJSON<T> returning Promise<T>, note response.json() is any, and show T lets callers lock in the response shape for compile-time checks.

TypeScript & Web APIs2 min read

Create a generic State class with getState and setState

Write class State<T> with private T, constructor(T), getState(): T, and setState(T).

TypeScript & Web APIs2 min read

Write a generic type-safe getProperty using keyof

Command of TypeScript generics and keyof for compile-time property access. Declare generic T, accept key as keyof T, and return T[K].

TypeScript & Web APIs2 min read

Explain generic constraints and provide a length-constrained generic example

Explain that extends requires properties; show T extends { length: number }; give a generic function signature.

TypeScript & Web APIs2 min read

Refactor a function using generics to accept any array type

It tests generic type parameters for preserving element types through a function boundary. Answer: declare T, accept T[], return T, and let the compiler infer the element type from the call site.

Download a large file via fetch and track ReadableStream progress
TypeScript & Web APIs2 min read

Download a large file via fetch and track ReadableStream progress

It tests streaming I/O and backpressure beyond Promise-based fetch. Acquire a reader from response.body, loop read() until done, sum chunk lengths against Content-Length, and emit progress.

When does fetch trigger a CORS preflight, and what POST is complex?
TypeScript & Web APIs2 min read

When does fetch trigger a CORS preflight, and what POST is complex?

Tests whether you know the simple-request boundary. A strong answer names the three safe POST content-types and gives a cross-origin POST with application/json plus a custom header like Authorization.

How do you cancel pending fetches using AbortController?
TypeScript & Web APIs2 min read

How do you cancel pending fetches using AbortController?

Keep one AbortController, abort before each fetch, pass its signal, and swallow AbortError.

Create a generic fetchJson wrapper with typed response and error handling
TypeScript & Web APIs2 min read

Create a generic fetchJson wrapper with typed response and error handling

Generic T parameter, optional RequestInit, throw if !res.ok, return res.json() as Promise<T>.

TypeScript & Web APIs2 min read

How do you handle an API returning 200 for success and failure?

This tests TypeScript narrowing and runtime validation of ambiguous 200 responses. A strong answer uses a discriminated union, narrows with a type guard, and validates shape before branching. Red flag: casting the body with as and skipping runtime checks.