Загрузка видео...

Не удалось загрузить видео

На главную

Some VINTAGE TypeScript magic. Here's how to create a type-safe version of Object.assign, with an arbitrary number of objects.

38,024 просмотров • 2 лет назад •via X (Twitter)

Комментарии: 10

Фото профиля Beppo
Beppo2 лет назад

Can anyone spot the bug in the code? If one argument of the merge has a partial property that is present in another obj. This type will create a wrong type and this could lead to bugs that are hard to spot. That's why most libs just intersect the objs

Фото профиля Matt Pocock
Matt Pocock2 лет назад

Great stuff! I suppose that filtering out partial properties during the Omit step would make sense.

Фото профиля eskimojo
eskimojo2 лет назад

honestly i don't find myself using Object.assign to mix different shapes, I'd rather use spread for that what i do tend to do is something like this (appears a couple times in the RTK codebase too)

Фото профиля Dan Gamble
Dan Gamble2 лет назад

That’s super insightful and pretty simple! Definitely need learn more about infer

Фото профиля CJ
CJ2 лет назад

Thank you so much for the explanation! Even the utility libs like lodash and remeda haven't solved this and are using brute force.

Фото профиля Bernardo Garcés
Bernardo Garcés2 лет назад

Nit, but using `object` means you can pass to your type something weird like a function `() => {}`. I'd have gone for `Record<string | number | symbol, unknown>`.

Фото профиля Uğur
Uğur2 лет назад

Pretty clever, love it ❤️

Фото профиля nitriques
nitriques2 лет назад

Very good Matt ! Prettify ftw (I will steal this)

Фото профиля Wollantine
Wollantine2 лет назад

Any idea if it is possible to type the merge of a generic [key: string]: string record with a value of a different type?

Фото профиля Fernando
Fernando1 год назад

@HeyGenLabs translate to Spanish

Похожие видео