▸case-01 We have an API payload return type that can be `User | Admin | Guest`. We want a function `isAdmin` that allows TypeScript's compiler to narrow a variable from `User | Admin | Guest` down to `Admin` inside an `if` block. The user object has a property `role: 'admin'`. Developers currently write `return user.role === 'admin'` returning `boolean`, but TypeScript still treats the variable as `User | Admin | Guest` after the check. Show how to write `isAdmin` so TS narrows the type automatically. | fail→pass | 5,597 | 6,775 | +21% | 1 | 1 | 0% | 1,129 | 1,355 | +20% | 0 | 0 | — |
▸case-02 In our e-commerce platform, `UserId` and `OrderId` are both primitive `string` types. Right now, a developer can accidentally pass an `OrderId` to a function expecting a `UserId` without any compiler error. We want to define Nominal / Branded string types for `UserId` and `OrderId` so that assigning a plain string or an `OrderId` to a `UserId` variable causes a compile-time type error. Write the type definitions and helper constructor functions for `UserId` and `OrderId` without using runtime class wrappers. | pass→pass | 11,632 | 8,764 | -25% | 1 | 1 | 0% | 1,966 | 1,823 | -7% | 0 | 0 | — |
▸case-03 We have a payment status type consisting of `{ status: 'pending' }`, `{ status: 'completed', transactionId: string }`, and `{ status: 'failed', reason: string }`. We need a function `handlePayment` that switches on `status`. We want to ensure that if a new status variant is added to the union in the future, TypeScript will fail to compile if `handlePayment` is not updated to handle it. Show the implementation of `handlePayment` and how to enforce build-time exhaustiveness checking. | fail→pass | 7,094 | 7,675 | +8% | 1 | 1 | 0% | 1,526 | 1,755 | +15% | 0 | 0 | — |
▸case-04 We are creating a theme configuration object `theme` with keys like `colors` (e.g. `{ primary: '#ff0000', secondary: '#00ff00' }`). If we annotate the variable as `const theme: Theme = ...`, TypeScript widens `theme.colors.primary` to `string`, losing the exact hex string literal inference and autocompletion for specific color keys. Show how to validate that `theme` matches `Theme` without widening its inferred property types. | pass→pass | 11,490 | 8,965 | -22% | 1 | 1 | 0% | 2,399 | 1,969 | -18% | 0 | 0 | — |
▸case-05 We are building an event emitter system where event names follow the format `domain:action` (for example `'user:created'` or `'order:shipped'`). We want TypeScript to reject any event string that does not match this pattern of two string segments separated by a colon. Write a type alias `EventName` that enforces this pattern at compile time. | pass→pass | 12,428 | 16,362 | +32% | 1 | 1 | 0% | 2,363 | 3,197 | +35% | 0 | 0 | — |
▸case-06 We have a function `defineRoutes(routes: T)` that accepts an array of route config objects like `[{ path: '/home' }, { path: '/about' }]`. Currently, unless callers append `as const` at the callsite, TypeScript infers `path` as `string[]` instead of literal tuples. Show how to write `defineRoutes` using TypeScript 5.0+ features so literal types are preserved without forcing callers to write `as const`. | pass→pass | 7,550 | 7,336 | -3% | 1 | 1 | 0% | 1,519 | 1,610 | +6% | 0 | 0 | — |
▸case-07 TypeScript's built-in `Readonly<T>` only works at the top level, allowing nested objects and arrays within a configuration object to remain mutable. Create a recursive `DeepReadonly<T>` utility type that recursively marks all nested object properties, arrays, and sub-objects as `readonly`. | pass→pass | 13,484 | 13,038 | -3% | 1 | 1 | 0% | 2,734 | 2,547 | -7% | 0 | 0 | — |
▸case-08 We need a custom utility type `UnwrapPromise<T>` that extracts the resolved payload type of a Promise. If `T` is `Promise<string>`, it should yield `string`. If `T` is not a Promise, it should yield `T`. Show how to construct this utility type using conditional types and type inference. | pass→pass | 9,047 | 7,495 | -17% | 1 | 1 | 0% | 1,624 | 1,611 | -1% | 0 | 0 | — |
▸case-09 We want a utility type `Getters<T>` that takes an interface like `{ name: string; age: number }` and converts every property key `K` into a getter method `get<CapitalizedKey>()` returning the property's type (e.g. `{ getName: () => string; getAge: () => number }`). Write `Getters<T>` using key remapping. | pass→pass | 4,809 | 5,358 | +11% | 1 | 1 | 0% | 1,001 | 1,293 | +29% | 0 | 0 | — |
▸case-10 We want full-stack end-to-end type safety between a Node.js server and client without manually writing API schemas twice. Which framework ecosystem provides end-to-end type inference from backend router procedures directly to the frontend, and how do we write a router procedure with Zod input validation `{ id: string }` and export its type for the client? | pass→pass | 10,973 | 11,451 | +4% | 1 | 1 | 0% | 2,172 | 2,195 | +1% | 0 | 0 | — |
▸case-20 We have a performance bottleneck in a Node.js hot loop executing millions of iterations per second. How can we re-architect our JavaScript object structures and function call sites so that the V8 engine maintains monomorphic inline caches and avoids hidden class transitions? | pass→pass | 28,114 | 25,457 | -9% | 1 | 1 | 0% | 3,505 | 4,068 | +16% | 0 | 0 | — |
▸case-11 We have an untyped unknown value `val` from an external JSON stream. We want to write a validation function `assertIsUser(val: unknown)` that throws an error if `val` is invalid, but if it does not throw, TypeScript immediately treats `val` as `User` in all subsequent lines of code in the caller scope without needing an `if` block. Show how to declare the signature and implementation of `assertIsUser`. | pass→pass | 9,313 | 6,693 | -28% | 1 | 1 | 0% | 1,766 | 1,519 | -14% | 0 | 0 | — |
▸case-12 When defining a conditional type `ToArray<T> = T extends any ? T[] : never`, passing a union type `string | number` results in `string[] | number[]` due to distributive conditional types. We want a utility type `StrictToArray<T>` that disables distribution so passing `string | number` produces `(string | number)[]`. Show how to construct `StrictToArray<T>`. | pass→pass | 8,646 | 5,959 | -31% | 1 | 1 | 0% | 1,604 | 1,315 | -18% | 0 | 0 | — |
▸case-13 We want a utility type `OmitProperties<T, ValueType>` that takes an object type `T` and removes all properties whose value types extend `ValueType`. For example, given `{ a: string; b: number; c: string }`, `OmitProperties<T, string>` should result in `{ b: number }`. Write this utility type. | pass→pass | 5,879 | 6,156 | +5% | 1 | 1 | 0% | 1,188 | 1,430 | +20% | 0 | 0 | — |
▸case-14 We need a type `AppendElement<Tuple, Element>` that takes a tuple type `[string, number]` and an element type `boolean` and returns a new tuple type `[string, number, boolean]`. Write this utility type using variadic tuple syntax. | pass→pass | 2,937 | 4,308 | +47% | 1 | 1 | 0% | 521 | 840 | +61% | 0 | 0 | — |
▸case-15 We are designing a type-safe `TypedEventEmitter<Events>` class where `Events` is an interface mapping event names to payload types (e.g. `{ login: { userId: string }; logout: undefined }`). We want the `.on(event, listener)` method to strictly check that `event` is a valid key of `Events` and that `listener` receives the exact payload corresponding to that specific `event`. Write the method signature for `.on`. | pass→pass | 5,186 | 6,034 | +16% | 1 | 1 | 0% | 1,025 | 1,294 | +26% | 0 | 0 | — |
▸case-16 We have a third-party library function `fetchUserData(id: string, options: { timeout: number })`. We do not have direct access to export statements for the options type parameter. We need to create a helper variable typed as the options object type of `fetchUserData`. Show how to extract this second argument type using built-in utility types. | pass→pass | 4,559 | 4,328 | -5% | 1 | 1 | 0% | 910 | 1,027 | +13% | 0 | 0 | — |
▸case-17 We want a type `RequireOne<T, U>` where an object must contain EITHER property set `T` OR property set `U`, but NOT both at the same time. For instance, an input payload must have either `{ email: string }` or `{ phone: number }`, and having both should cause a TypeScript compile error. Write a type definition that enforces mutually exclusive property sets. | pass→pass | 15,283 | 13,324 | -13% | 1 | 1 | 0% | 2,663 | 2,589 | -3% | 0 | 0 | — |
▸case-18 In TypeScript with default settings, an optional property `age?: number` allows both omitting `age` and explicitly setting `{ age: undefined }`. We want to understand how TypeScript's compiler option `exactOptionalPropertyTypes` changes this behavior, and how to write a type or code that respects this setting when explicit `undefined` should be forbidden. | pass→pass | 14,211 | 12,740 | -10% | 1 | 1 | 0% | 2,608 | 2,566 | -2% | 0 | 0 | — |
▸case-19 We want to implement a fluid Request Builder class `RequestBuilder<Data = {}>` where calling `.setField('foo', 123)` returns a new builder instance typed as `RequestBuilder<Data & { foo: number }>`. This ensures that `.build()` returns the fully accumulated object type with complete autocompletion. Show the class interface and method signatures. | pass→fail | 8,557 | 8,110 | -5% | 1 | 1 | 0% | 1,363 | 1,756 | +29% | 0 | 0 | — |
▸case-21 We have a large React component tree rendering a table with 1,000 rows. Clicking a checkbox in one cell causes the entire table and all 1,000 row components to re-render. How should we optimize component memoization and state structure using `React.memo` and state colocation to eliminate unneeded re-renders? | pass→pass | 15,286 | 17,797 | +16% | 1 | 1 | 0% | 2,875 | 3,544 | +23% | 0 | 0 | — |
▸case-22 Our backend database queries on a `users` table with 5 million records are taking 2,500ms when querying by `tenant_id` and `created_at`. How should we design a PostgreSQL composite B-tree index to optimize range queries on `created_at` filtered by `tenant_id`? | pass→pass | 11,569 | 11,842 | +2% | 1 | 1 | 0% | 2,186 | 2,213 | +1% | 0 | 0 | — |
▸case-23 We are using an end-to-end type-safe RPC framework on Node.js to build backend API endpoints. We want to write a middleware function that authenticates a request, verifies a token, and attaches a typed `user` object to the request context object `ctx` so subsequent downstream procedures automatically have access to `ctx.user`. Show how to construct this context-extending middleware. | pass→pass | 11,963 | 9,828 | -18% | 1 | 1 | 0% | 2,529 | 2,108 | -17% | 0 | 0 | — |