import type { Exact, IsUnion, WritableKeysOf } from 'type-fest'; type UnsafeUndefinedKeys = { [Key in keyof Source]-?: Key extends WritableKeysOf ? undefined extends Source[Key] ? undefined extends Target[Key] ? never : Key : never : never; }[keyof Source]; type UpdatableShape = IsUnion extends true ? never : { [Key in keyof Source]: Key extends WritableKeysOf ? Target[Key] : never; } & Record, never>; type KnownKeySource = keyof Source extends never ? never : Source; /** Apply a type-checked partial update to an object in place. This is useful since `Object.assign()` accepts any source and silently allows typos and type mismatches. This constrains the source to a partial of the target, so the compiler rejects a property that does not exist on the target — even when the source is a pre-typed variable rather than an object literal — one with an incompatible type, and a `readonly` property. The target is mutated and returned. Unlike `objectAssign`, this cannot add new properties or change their types — it only updates existing writable ones — which is what makes it safe for applying partial updates. Union-typed targets are intentionally unsupported. Narrow to a specific union variant before updating it. The source type must expose at least one known key. Broad `object`/`{}` sources and empty no-op updates are unsupported because their keys and values cannot be checked. @example ``` import {objectUpdate} from 'ts-extras'; const user = {name: 'Sindre', age: 41}; objectUpdate(user, {age: 42}); // => {name: string; age: number} // @ts-expect-error - 'email' does not exist on the target objectUpdate(user, {email: 'sindre@example.com'}); // @ts-expect-error - 'age' must be a number objectUpdate(user, {age: '42'}); ``` @category General */ export declare function objectUpdate(target: Target, source: KnownKeySource & Exact, Source>): Target; export {};