diff --git a/types/index.d.ts b/types/index.d.ts index b33dc5dc35..0fb54b4e0c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -622,26 +622,33 @@ export function renameKeys>( obj: OBJ ) => PickRenameMulti; + +type Keyable = string | number | symbol +type RenameObjectKey< + OKey extends keyof OBJ, + OBJ extends { readonly [s in OKey]: any }, + NKey extends Keyable, +> = Omit & Record + /** * Creates a new object with the own properties of the provided object, but a - * single key is renamed according to the currentKey as `'oldKey'` and newKey as `'newKey'`. - * When some key is not found in the currentKey, then it's passed as-is. + * single key is renamed from `oldKey` to `newKey`. */ - function renameKey< - KEYS extends keyof OBJ, - OBJ extends { readonly [s in KEYS]: any } ->(currentKey: KEYS, newKey: string): (obj: OBJ) => OBJ; - + OKey extends Keyable, +>(oldKey: OKey): + (newKey: NKey) => + (obj: OBJ) => RenameObjectKey; function renameKey< - KEYS extends keyof OBJ, - OBJ extends { readonly [s in KEYS]: any } ->(currentKey: KEYS): (newKey: string) => (obj: OBJ) => OBJ; - + OKey extends Keyable, + NKey extends Keyable, +>(oldKey: OKey, newKey: NKey): + (obj: OBJ) => RenameObjectKey; function renameKey< - KEYS extends keyof OBJ, - OBJ extends { readonly [s in KEYS]: any } ->(currentKey: KEYS, newKey: string, obj: OBJ): OBJ; + OKey extends keyof OBJ, + OBJ extends { readonly [s in OKey]: any }, + NKey extends Keyable, +>(oldKey: OKey, newKey: NKey, obj: OBJ): RenameObjectKey /** * Creates a new object with the own properties of the provided object, and the