{
[K in keyof (keyof T & keyof U extends never
? T & U
: Omit<T, keyof T & keyof U> & U)]: (keyof T & keyof U extends never
? T & U
: Omit<T, keyof T & keyof U> & U)[K]
}Merges two object types with properties from U taking precedence over T
on overlapping keys (like Object.assign at the type level).
When to use
Use when you need the type-level equivalent of { ...T, ...U }.
Details
When no keys overlap, this returns a simple intersection for efficiency.
When keys overlap, the type from U wins.
Example (Merging two types with overlapping keys)
import type { Struct } from "effect"
type A = { a: string; b: number }
type B = { b: boolean; c: string }
type Merged = Struct.Assign<A, B>
// { a: string; b: boolean; c: string }export type type Assign<T, U> = {
[K in keyof (keyof T & keyof U extends never
? T & U
: Omit<T, keyof T & keyof U> & U)]: (keyof T &
keyof U extends never
? T & U
: Omit<T, keyof T & keyof U> & U)[K]
}
Merges two object types with properties from U taking precedence over T
on overlapping keys (like Object.assign at the type level).
When to use
Use when you need the type-level equivalent of { ...T, ...U }.
Details
When no keys overlap, this returns a simple intersection for efficiency.
When keys overlap, the type from U wins.
Example (Merging two types with overlapping keys)
import type { Struct } from "effect"
type A = { a: string; b: number }
type B = { b: boolean; c: string }
type Merged = Struct.Assign<A, B>
// { a: string; b: boolean; c: string }
Assign<function (type parameter) T in type Assign<T, U>T, function (type parameter) U in type Assign<T, U>U> = type Simplify<T> = {
[K in keyof T]: T[K]
}
Flattens intersection types into a single object type for readability.
When to use
Use when hovering over a type shows A & B & C instead of the merged shape.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It preserves readonly modifiers; use
Mutable
to strip them.
Example (Flattening an intersection)
import type { Struct } from "effect"
type Original = { a: string } & { b: number }
// Without Simplify, the type displays as `{ a: string } & { b: number }`
type Simplified = Struct.Simplify<Original>
// { a: string; b: number }
Simplify<keyof function (type parameter) T in type Assign<T, U>T & keyof function (type parameter) U in type Assign<T, U>U extends never ? function (type parameter) T in type Assign<T, U>T & function (type parameter) U in type Assign<T, U>U : type Omit<T, K extends keyof any> = {
[P in Exclude<keyof T, K>]: T[P]
}
Construct a type with the properties of T except for those in type K.
Omit<function (type parameter) T in type Assign<T, U>T, keyof function (type parameter) T in type Assign<T, U>T & keyof function (type parameter) U in type Assign<T, U>U> & function (type parameter) U in type Assign<T, U>U>