Skip to the solution
MediumFrontend14 min read

What's new to type in TypeScript 5.5+ libs — Array.fromAsync, Set methods, Iterator helpers?

431 views

The problem

Question presented to candidate: "Recent TypeScript releases added types for Set.prototype.union, iterator helpers like values().map().take(), and Array.fromAsync. How do you get those types in a project, what do the signatures look like, and what does TypeScript not do for you here?"

What a strong answer should cover:

  • Built-in API types come from the lib setting (defaulted from target); new proposals land in esnext.* libs first: Set methods in esnext.collection (TypeScript 5.5), iterator helpers in esnext.iterator (5.6), Array.fromAsync in esnext.array
  • Types are not polyfills: lib only says the methods exist; the engine (or a polyfill) must actually have them
  • Set methods: union<U>(other: ReadonlySetLike<U>): Set<T | U>, intersection gives Set<T & U>, difference keeps Set<T>; "set-like" means size, has, keys (a Map qualifies, an array does not)
  • Iterator helpers are lazy and return IteratorObject<T, undefined, unknown>; 5.6 introduced IteratorObject, ArrayIterator and friends plus BuiltinIteratorReturn and the --strictBuiltinIteratorReturn strict flag
  • Array.fromAsync returns Promise<T[]>, awaiting each element in order (unlike Promise.all)
  • Version detail: in TypeScript 6.0 the Set and iterator types moved to an es2025 lib, while fromAsync stays in esnext

Code / implementation expected: Optional — a tsconfig lib change plus a few typed calls, or a typed userland equivalent.

  • esnext
  • lib-types

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

14 min read · 10 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

TypeScriptSet operations with the lib signatures (union, intersection, difference)
TypeScriptLazy iterator helpers and a typed fromAsync

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 48 of 81 in TypeScript

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextMedium

What is the Record utility type?

Continue