| 1 | /**
|
|---|
| 2 | * Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|---|
| 3 | * It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|---|
| 4 | *
|
|---|
| 5 | * You can provide multiple source objects to set these default values,
|
|---|
| 6 | * and they will be applied in the order they are given, from left to right.
|
|---|
| 7 | * Once a property has been set, any later values for that property will be ignored.
|
|---|
| 8 | *
|
|---|
| 9 | * Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|---|
| 10 | *
|
|---|
| 11 | * Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|---|
| 12 | *
|
|---|
| 13 | * @template T - The type of the object being processed.
|
|---|
| 14 | * @param {T} object - The target object.
|
|---|
| 15 | * @returns {T} The cloned object.
|
|---|
| 16 | */
|
|---|
| 17 | declare function toDefaulted<T extends object>(object: T): T;
|
|---|
| 18 | /**
|
|---|
| 19 | * Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|---|
| 20 | * It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|---|
| 21 | *
|
|---|
| 22 | * You can provide multiple source objects to set these default values,
|
|---|
| 23 | * and they will be applied in the order they are given, from left to right.
|
|---|
| 24 | * Once a property has been set, any later values for that property will be ignored.
|
|---|
| 25 | *
|
|---|
| 26 | * Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|---|
| 27 | *
|
|---|
| 28 | * @template T - The type of the object being processed.
|
|---|
| 29 | * @template S - The type of the object that provides default values.
|
|---|
| 30 | * @param {T} object - The target object that will receive default values.
|
|---|
| 31 | * @param {S} source - The object that specifies the default values to apply.
|
|---|
| 32 | * @returns {NonNullable<T & S>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|---|
| 33 | */
|
|---|
| 34 | declare function toDefaulted<T extends object, S extends object>(object: T, source: S): NonNullable<T & S>;
|
|---|
| 35 | /**
|
|---|
| 36 | * Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|---|
| 37 | * It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|---|
| 38 | *
|
|---|
| 39 | * You can provide multiple source objects to set these default values,
|
|---|
| 40 | * and they will be applied in the order they are given, from left to right.
|
|---|
| 41 | * Once a property has been set, any later values for that property will be ignored.
|
|---|
| 42 | *
|
|---|
| 43 | * Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|---|
| 44 | *
|
|---|
| 45 | * @template T - The type of the object being processed.
|
|---|
| 46 | * @template S1 - The type of the first object that provides default values.
|
|---|
| 47 | * @template S2 - The type of the second object that provides default values.
|
|---|
| 48 | * @param {T} object - The target object that will receive default values.
|
|---|
| 49 | * @param {S1} source1 - The first object that specifies the default values to apply.
|
|---|
| 50 | * @param {S2} source2 - The second object that specifies the default values to apply.
|
|---|
| 51 | * @returns {NonNullable<T & S1 & S2>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|---|
| 52 | */
|
|---|
| 53 | declare function toDefaulted<T extends object, S1 extends object, S2 extends object>(object: T, source1: S1, source2: S2): NonNullable<T & S1 & S2>;
|
|---|
| 54 | /**
|
|---|
| 55 | * Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|---|
| 56 | * It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|---|
| 57 | *
|
|---|
| 58 | * You can provide multiple source objects to set these default values,
|
|---|
| 59 | * and they will be applied in the order they are given, from left to right.
|
|---|
| 60 | * Once a property has been set, any later values for that property will be ignored.
|
|---|
| 61 | *
|
|---|
| 62 | * Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|---|
| 63 | *
|
|---|
| 64 | * @template T - The type of the object being processed.
|
|---|
| 65 | * @template S1 - The type of the first object that provides default values.
|
|---|
| 66 | * @template S2 - The type of the second object that provides default values.
|
|---|
| 67 | * @template S3 - The type of the third object that provides default values.
|
|---|
| 68 | * @param {T} object - The target object that will receive default values.
|
|---|
| 69 | * @param {S1} source1 - The first object that specifies the default values to apply.
|
|---|
| 70 | * @param {S2} source2 - The second object that specifies the default values to apply.
|
|---|
| 71 | * @param {S3} source3 - The third object that specifies the default values to apply.
|
|---|
| 72 | * @returns {NonNullable<T & S1 & S2 & S3>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|---|
| 73 | */
|
|---|
| 74 | declare function toDefaulted<T extends object, S1 extends object, S2 extends object, S3 extends object>(object: T, source1: S1, source2: S2, source3: S3): NonNullable<T & S1 & S2 & S3>;
|
|---|
| 75 | /**
|
|---|
| 76 | * Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|---|
| 77 | * It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|---|
| 78 | *
|
|---|
| 79 | * You can provide multiple source objects to set these default values,
|
|---|
| 80 | * and they will be applied in the order they are given, from left to right.
|
|---|
| 81 | * Once a property has been set, any later values for that property will be ignored.
|
|---|
| 82 | *
|
|---|
| 83 | * Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|---|
| 84 | *
|
|---|
| 85 | * @template T - The type of the object being processed.
|
|---|
| 86 | * @template S1 - The type of the first object that provides default values.
|
|---|
| 87 | * @template S2 - The type of the second object that provides default values.
|
|---|
| 88 | * @template S3 - The type of the third object that provides default values.
|
|---|
| 89 | * @template S4 - The type of the fourth object that provides default values.
|
|---|
| 90 | * @param {T} object - The target object that will receive default values.
|
|---|
| 91 | * @param {S1} source1 - The first object that specifies the default values to apply.
|
|---|
| 92 | * @param {S2} source2 - The second object that specifies the default values to apply.
|
|---|
| 93 | * @param {S3} source3 - The third object that specifies the default values to apply.
|
|---|
| 94 | * @param {S4} source4 - The fourth object that specifies the default values to apply.
|
|---|
| 95 | * @returns {NonNullable<T & S1 & S2 & S3 & S4>} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|---|
| 96 | */
|
|---|
| 97 | declare function toDefaulted<T extends object, S1 extends object, S2 extends object, S3 extends object, S4 extends object>(object: T, source1: S1, source2: S2, source3: S3, source4: S4): NonNullable<T & S1 & S2 & S3 & S4>;
|
|---|
| 98 | /**
|
|---|
| 99 | * Creates a new object based on the provided `object`, applying default values from the `sources` to ensure that no properties are left `undefined`.
|
|---|
| 100 | * It assigns default values to properties that are either `undefined` or come from `Object.prototype`.
|
|---|
| 101 | *
|
|---|
| 102 | * You can provide multiple source objects to set these default values,
|
|---|
| 103 | * and they will be applied in the order they are given, from left to right.
|
|---|
| 104 | * Once a property has been set, any later values for that property will be ignored.
|
|---|
| 105 | *
|
|---|
| 106 | * Note: This function creates a new object. If you want to modify the `object`, use the `defaults` function instead.
|
|---|
| 107 | *
|
|---|
| 108 | * @template T - The type of the object being processed.
|
|---|
| 109 | * @template S - The type of the objects that provides default values.
|
|---|
| 110 | * @param {T} object - The target object that will receive default values.
|
|---|
| 111 | * @param {S[]} sources - The objects that specifies the default values to apply.
|
|---|
| 112 | * @returns {object} A new object that combines the target and default values, ensuring no properties are left undefined.
|
|---|
| 113 | *
|
|---|
| 114 | * @example
|
|---|
| 115 | * toDefaulted({ a: 1 }, { a: 2, b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|---|
| 116 | * toDefaulted({ a: 1, b: 2 }, { b: 3 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|---|
| 117 | * toDefaulted({ a: null }, { a: 1 }); // { a: null }
|
|---|
| 118 | * toDefaulted({ a: undefined }, { a: 1 }); // { a: 1 }
|
|---|
| 119 | */
|
|---|
| 120 | declare function toDefaulted<T extends object, S extends object>(object: T, ...sources: S[]): object;
|
|---|
| 121 |
|
|---|
| 122 | export { toDefaulted };
|
|---|