Promise.all with John Chadwick - TypeScript Type Challenges #20 [MEDIUM]

preview_player
Показать описание

00:00 description of the challenge
01:12 attempt at a solution
05:11 all tests pass

Рекомендации по теме
Комментарии
Автор

I really like the fact that the challenges keep increasing in the difficulty, but somehow, it still increases in how easy is to understand. Excited to see how advanced challenges will be

fagnersales
Автор

The thing most crucial and hardest to understand here IMO is the need for readonly [...T] and not readonly T (which won't work). I'm trying to figure out why that is strictly needed here.

gnorts_mr_alien
Автор

2:25 It was very lucky to write <T extends unknown[]>(values: [...T]) and not <T extends readonly unknown[]>(values: T). I spent 4 minutes fixing test for A2, but I somehow remembered that T and [...T] may have such difference.
4:30 This Awaited is now in standard library since 4.5. Also it was among this challenges as 00189-easy-awaited.

QwDragon
Автор

This is one of the most unintuitive aspects of typescript imo. The fact that a type mapped over a tuple represents a new tuple makes sense when described, but syntatically it always looks like I’m defining a plain object shape and not a tuple.

kasper_
Автор

type PromiseFlat<T> = T extends Promise<infer R> ? PromiseFlat<R> : T

declare function PromiseAll<T extends unknown[]>(
values: readonly [...T]
): Promise<{
[K in keyof T]: PromiseFlat<T[K]>
}>

yunhaiwang
Автор

I wrote "[P in keyof T]: T[P] extends Promise<infer R> ? R : T[P]" firstly, but the last case didn't pass until I replace it with Awated<T[P]> after watching your video.Thanks for helping me😁.But I just want to know why the former method didn't work?

Driver_kw_