diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74b0b23..7ab1f33 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: ['20', '18', '16'] + node: ['24', '22', '20'] name: Node ${{ matrix.node }} steps: - name: Checkout repository diff --git a/package-lock.json b/package-lock.json index e2561e4..75d0554 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "types-ramda", - "version": "0.30.1", + "version": "0.31.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "types-ramda", - "version": "0.30.1", + "version": "0.31.0", "license": "MIT", "dependencies": { "ts-toolbelt": "^9.6.0" @@ -17,7 +17,7 @@ "dox": "^1.0.0", "eslint": "^8.50.0", "eslint-plugin-import": "^2.28.1", - "ramda": "^0.30.1", + "ramda": "^0.31.3", "rimraf": "^5.0.5", "tsd": "^0.31.0", "typescript": "^5.2.2", @@ -3115,10 +3115,11 @@ } }, "node_modules/ramda": { - "version": "0.30.1", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.30.1.tgz", - "integrity": "sha512-tEF5I22zJnuclswcZMc8bDIrwRHRzf+NqVEmqg50ShAZMP7MWeR/RGDthfM/p+BlqvF2fXAzpn8i+SJcYD3alw==", + "version": "0.31.3", + "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.31.3.tgz", + "integrity": "sha512-xKADKRNnqmDdX59PPKLm3gGmk1ZgNnj3k7DryqWwkamp4TJ6B36DdpyKEQ0EoEYmH2R62bV4Q+S0ym2z8N2f3Q==", "dev": true, + "license": "MIT", "funding": { "type": "opencollective", "url": "https://opencollective.com/ramda" @@ -6263,9 +6264,9 @@ "dev": true }, "ramda": { - "version": "0.30.1", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.30.1.tgz", - "integrity": "sha512-tEF5I22zJnuclswcZMc8bDIrwRHRzf+NqVEmqg50ShAZMP7MWeR/RGDthfM/p+BlqvF2fXAzpn8i+SJcYD3alw==", + "version": "0.31.3", + "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.31.3.tgz", + "integrity": "sha512-xKADKRNnqmDdX59PPKLm3gGmk1ZgNnj3k7DryqWwkamp4TJ6B36DdpyKEQ0EoEYmH2R62bV4Q+S0ym2z8N2f3Q==", "dev": true }, "react-is": { diff --git a/package.json b/package.json index 6465e93..1c58cdd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "types-ramda", - "version": "0.30.1", + "version": "0.31.0", "description": "Dedicated types library for ramda", "author": "Harris Miller ", "contributors": [ @@ -67,7 +67,7 @@ "dox": "^1.0.0", "eslint": "^8.50.0", "eslint-plugin-import": "^2.28.1", - "ramda": "^0.30.1", + "ramda": "^0.31.3", "rimraf": "^5.0.5", "tsd": "^0.31.0", "typescript": "^5.2.2", diff --git a/test/renameKeys.test.ts b/test/renameKeys.test.ts new file mode 100644 index 0000000..554416e --- /dev/null +++ b/test/renameKeys.test.ts @@ -0,0 +1,19 @@ +import { expectAssignable, expectType } from 'tsd'; + +import { __, renameKeys } from '../es'; + +expectType<{ bar: number; other: string }>(renameKeys({ foo: 'bar' })({ foo: 123, other: 'abc' })); +expectType<{ foo: number; blah: string }>(renameKeys({ other: 'blah' })({ foo: 123, other: 'abc' })); + +expectType<{ bar: number; other: string }>(renameKeys(__, { foo: 123, other: 'abc' })({ foo: 'bar' })); +expectType<{ foo: number; blah: string }>(renameKeys(__, { foo: 123, other: 'abc' })({ other: 'blah' })); + +expectType<{ bar: number; other: string }>(renameKeys({ foo: 'bar' }, { foo: 123, other: 'abc' })); +expectType<{ foo: number; blah: string }>(renameKeys({ other: 'blah' }, { foo: 123, other: 'abc' })); + +const nonConstObj = { foo: 'bar' }; + +const what = renameKeys(nonConstObj, { foo: 123, other: 'abc' }); +// ^? +// @ts-expect-error - I have no idea why declaring the type throws an error, but it can be calculated above +expectAssignable<{ [x: string]: number; other: string; }>(what); diff --git a/types/renameKeys.d.ts b/types/renameKeys.d.ts new file mode 100644 index 0000000..a042cfe --- /dev/null +++ b/types/renameKeys.d.ts @@ -0,0 +1,8 @@ +import { Placeholder, Prettify, Remap } from './util/tools'; + +// renameKeys(mapping)(obj) +export function renameKeys>(mapping: U): >(obj: T) => Prettify & Remap>; +// renameKeys(__, obj)(mapping) +export function renameKeys(__: Placeholder, obj: T): >>(mapping: U) => Prettify & Remap>; +// renameKeys(mapping, obj) +export function renameKeys>>(mapping: U, obj: T): Prettify & Remap>; diff --git a/types/util/tools.d.ts b/types/util/tools.d.ts index 18687cd..679e629 100644 --- a/types/util/tools.d.ts +++ b/types/util/tools.d.ts @@ -520,3 +520,28 @@ export type NonEmptyArray = [T, ...T[]]; * */ export type ReadonlyNonEmptyArray = readonly [T, ...T[]]; + +/** + * Prettify type into an object literal + * + */ +export type Prettify = {[KeyType in keyof T]: T[KeyType]} & {}; + +type TuplesFromObject = { + [P in keyof T]: [P, T[P]]; +}[keyof T]; + +type GetKeyByValue = + TuplesFromObject extends infer TT + ? TT extends [infer P, V] + ? P + : never + : never; + +/** + * Remap keys of one object to the values of mapping object + * + */ +export type Remap = { + [P in NonNullable]: T[GetKeyByValue]; +};