DEV Community

loading...

Discussion on: Typescript — how to Deep merge

Collapse
faiwer profile image
Stepan Zubashev • Edited

Great article. Thank you for it! The more TS recepies we have the better types we can write. Especially thanks for this hack with a tuple and if-else.

One note: There's type PropertyKey. It'd be better to use it instead of string. But... TS dissalow it. It even dissallows using string | number. Hm...

P.S. a translated this article to Russian there ( habr.com/en/post/526998/ ).

Collapse
svehla profile image
Jakub Švehla Author • Edited

Hi dude

Thanks a lot for the translation 😇 a read the comments below and that pretty nice 💪
some guy found issue with merging inconsistent arrays [{ a: 'a' }, { b: 'b'}]... I know about it and I already resolved it... but the solution is too complicated (and large) to keep it in one article... So I have a plan to do the second part of it where I'll resolve this edge-case + Add the optional length of types to merge... something like: DeepMergeMany<A, B, C, D, ...>

So I'll see 😏

Collapse
svehla profile image
Jakub Švehla Author

Hi @stepan Zubaslev! It took few months but I did it! :D

I just refactored half of the article and I add

  • Support for better typescript help
  • Fix many edge cases which I mention a few months ago.

At the moment the basic type like { a: [{ a: 'a' }, { b: 'b'}] } is working and DeepMergeTwoTypes<T, U> generic will resolve and merge this array (tuple) structure correctly, like in the screenshots in the article.

I hope you'll like these newly refactored upgrades!