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
libsetting (defaulted fromtarget); new proposals land inesnext.*libs first: Set methods inesnext.collection(TypeScript 5.5), iterator helpers inesnext.iterator(5.6),Array.fromAsyncinesnext.array - Types are not polyfills:
libonly says the methods exist; the engine (or a polyfill) must actually have them - Set methods:
union<U>(other: ReadonlySetLike<U>): Set<T | U>,intersectiongivesSet<T & U>,differencekeepsSet<T>; "set-like" meanssize,has,keys(aMapqualifies, an array does not) - Iterator helpers are lazy and return
IteratorObject<T, undefined, unknown>; 5.6 introducedIteratorObject,ArrayIteratorand friends plusBuiltinIteratorReturnand the--strictBuiltinIteratorReturnstrict flag Array.fromAsyncreturnsPromise<T[]>, awaiting each element in order (unlikePromise.all)- Version detail: in TypeScript 6.0 the Set and iterator types moved to an
es2025lib, whilefromAsyncstays inesnext
Code / implementation expected: Optional — a tsconfig lib change plus a few typed calls, or a typed userland equivalent.