Last active
February 4, 2022 09:40
-
-
Save msereniti/44b4aaa1d95fd5327109ae2dfc16643f to your computer and use it in GitHub Desktop.
Typescript shallow merge multiple objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ArrShift<Arr extends any[]> = Arr extends [skip: any, ...use: infer Use] | |
? Use | |
: Arr; | |
type ShallowMerge<Args extends any[]> = Args extends [any, any, any, ...any] ? Args[0] & ShallowMerge<ArrShift<Args>> : Args extends [any, any] ? Args[0] & Args[1] : Args[0] | |
type X = ShallowMerge<[{ x: 1 }, { y: 2 }, { z: 3}, { w: 4}]> | |
const x = 0 as any as X | |
x.x | |
x.y | |
x.z | |
x.w |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment