MergeRight<Target, Source>Right-biased merge of two object types where keys from Source take
precedence over Target on conflict.
When to use
Use when you want right-biased merging where the second argument wins.
Details
The result is automatically simplified via Simplify.
Example (Right-biased merge)
import type { Types } from "effect"
type Result = Types.MergeRight<
{ a: number; b: number },
{ a: string; c: boolean }
>
// { a: string; b: number; c: boolean }export type type MergeRight<Target, Source> = {
[K in keyof (Source & {
[Key in keyof Target as Key extends keyof Source
? never
: Key]: Target[Key]
})]: (Source & {
[Key in keyof Target as Key extends keyof Source
? never
: Key]: Target[Key]
})[K]
} extends infer B
? B
: never
Right-biased merge of two object types where keys from Source take
precedence over Target on conflict.
When to use
Use when you want right-biased merging where the second argument wins.
Details
The result is automatically simplified via
Simplify
.
Example (Right-biased merge)
import type { Types } from "effect"
type Result = Types.MergeRight<
{ a: number; b: number },
{ a: string; c: boolean }
>
// { a: string; b: number; c: boolean }
MergeRight<function (type parameter) Target in type MergeRight<Target, Source>Target, function (type parameter) Source in type MergeRight<Target, Source>Source> = type Simplify<A> = {
[K in keyof A]: A[K]
} extends infer B
? B
: never
Flattens an intersection type into a single object type for readability.
When to use
Use to clean up IDE tooltips that show A & B & C instead of a merged
object.
Details
Does not change the type semantically, only its display.
Example (Simplifying an intersection)
import type { Types } from "effect"
// Without Simplify: IDE shows { a: number } & { b: string }
// With Simplify: IDE shows { a: number; b: string }
type Clean = Types.Simplify<{ a: number } & { b: string }>
Simplify<
& function (type parameter) Source in type MergeRight<Target, Source>Source
& {
[function (type parameter) KeyKey in keyof function (type parameter) Target in type MergeRight<Target, Source>Target as function (type parameter) KeyKey extends keyof function (type parameter) Source in type MergeRight<Target, Source>Source ? never : function (type parameter) KeyKey]: function (type parameter) Target in type MergeRight<Target, Source>Target[function (type parameter) KeyKey]
}
>