Skip to content

Commit

Permalink
chore@small
Browse files Browse the repository at this point in the history
  • Loading branch information
selfrefactor committed Feb 3, 2025
1 parent 8cb13dc commit 1157bfb
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 78 deletions.
8 changes: 8 additions & 0 deletions files/NEXT_VERSION_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ _ Regarding using object as input with TypeScript in methods such as `R.map/filt
-- either
-- filter
-- forEach
-- pluck
-- keys
-- map
-- mapObjIndexed
-- mergeAll
-- mergeWith
-- modify
-- propEq
-- modifyPath
-- omit
-- partition
Expand All @@ -97,6 +99,12 @@ _ Regarding using object as input with TypeScript in methods such as `R.map/filt
- Publish to JSR registry - https://jsr.io/@rambda/rambda

- Replace Record<string> with Record<PropertyKey>

- Improve TypeScript definitions of:

-- objOf
-- pluck

===
Rambdax
change
Expand Down
22 changes: 10 additions & 12 deletions files/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2856,8 +2856,8 @@ Notes:
*/
// @SINGLE_MARKER
export function objOf<T, K extends string>(key: K, value: T): Record<K, T>;
export function objOf<K extends string>(key: K): <T>(value: T) => Record<K, T>;
export function objOf<T, K extends PropertyKey>(key: K, value: T) : { [P in K]: T };
export function objOf<T, K extends PropertyKey>(key: K): (value: T) => { [P in K]: T };

/*
Method: once
Expand Down Expand Up @@ -3428,14 +3428,12 @@ const result = R.pluck(property, list)
Categories: List, Object
Notes:
Notes: pipe
*/
// @SINGLE_MARKER
export function pluck<K extends keyof T, T>(property: K, list: T[]): T[K][];
export function pluck<T>(property: number, list: { [k: number]: T }[]): T[];
export function pluck<P extends string>(property: P): <T>(list: Record<P, T>[]) => T[];
export function pluck(property: number): <T>(list: { [k: number]: T }[]) => T[];
export function pluck<T, K extends keyof T>(property: K): (list: T[]) => T[K][];
export function pluck<T, K extends keyof T>(property: K, list: T[]): T[K][];

/*
Method: prepend
Expand Down Expand Up @@ -3534,12 +3532,12 @@ Notes:
*/
// @SINGLE_MARKER
export function propEq<K extends string | number>(valueToMatch: any, propToFind: K, obj: Record<K, any>): boolean;
export function propEq<K extends string | number>(valueToMatch: any, propToFind: K): (obj: Record<K, any>) => boolean;
export function propEq(valueToMatch: any): {
<K extends string | number>(propToFind: K, obj: Record<K, any>): boolean;
<K extends string | number>(propToFind: K): (obj: Record<K, any>) => boolean;
export function propEq<T>(val: T): {
<K extends PropertyKey>(name: K): (obj: Record<K, T>) => boolean;
<K extends PropertyKey>(name: K, obj: Record<K, T>): boolean;
};
export function propEq<T, K extends PropertyKey>(val: T, name: K): (obj: Record<K, T>) => boolean;
export function propEq<K extends keyof U, U>(val: U[K], name: K, obj: U): boolean;

/*
Method: propIs
Expand Down
3 changes: 2 additions & 1 deletion source/modifyPath-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const obj = {a: {b: {c: 1}}}

describe('R.modifyPath', () => {
it('happy', () => {
const result = modifyPath('a.b.c', (x: number) => x + 1, obj)
const result = modifyPath(['a', 'b', 'c'], (x: number) => String(x), obj)
result // $ExpectType Record<string, unknown>
result.a.b.c // $ExpectType string
})
it('explicit return type', () => {
interface Foo extends Record<string, unknown> {
Expand Down
16 changes: 10 additions & 6 deletions source/objOf-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {objOf} from 'rambda'
import {objOf, piped} from 'rambda'

const key = 'foo'
const value = 42
Expand All @@ -12,9 +12,13 @@ describe('R.objOf', () => {
// @ts-expect-error
result.bar
})
it('curried', () => {
const result = objOf(key)(value)

result.foo // $ExpectType number
})
it('inside piped', () => {
const result = piped(
value,
objOf(key)
)
result.foo // $ExpectType number
// @ts-expect-error
result.bar
})
})
8 changes: 0 additions & 8 deletions source/pipe-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,3 @@ describe('R.pipe', () => {
result; // $ExpectType void
});
});

describe('R.pipe - @types/ramda tests', () => {
test('complex', () => {
const fn = pipe(Math.pow, negate, inc, inc, inc, inc, inc, inc, inc, inc);
const result = fn(3, 4);
result; // $ExpectType number
});
});
5 changes: 1 addition & 4 deletions source/piped-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ function tapFn<T, U>(transformFn: (x: T) => U, fn: (a: T, b: U) => void): (x: T)
};
}

/**
reject
*/
describe('real use cases - books', () => {
it('case 1', () => {
const result = piped(
Expand All @@ -163,7 +160,7 @@ describe('real use cases - books', () => {
}),
tapFn(union([awardedBrothersKaramazov]),(a, b) => {
a; // $ExpectType Book[]
b; // $ExpectType boolean
b; // $ExpectType Book[]
}),
find(x => {
x // $ExpectType Book
Expand Down
61 changes: 37 additions & 24 deletions source/pluck-spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
import {pluck} from 'rambda'
import {piped, pluck} from 'rambda'

describe('R.pluck', () => {
it('with object', () => {
interface ListMember {
a: number,
b: string,
}
const input: ListMember[] = [
{a: 1, b: 'foo'},
{a: 2, b: 'bar'},
]
describe('R.pluck - with property key', () => {
const input = [
{a: 1, b: 'foo'},
{a: 2, b: 'bar'},
]
it('inside piped', () => {
const result = piped(
input,
pluck('b')
)
result // $ExpectType string[]
})
it('without currying', () => {
const resultA = pluck('a', input)
const resultB = pluck('b')(input)
resultA // $ExpectType number[]
resultB // $ExpectType string[]
})

it('with array', () => {
const input = [
[1, 2],
[3, 4],
[5, 6],
]
const result = pluck(0, input)
const resultCurry = pluck(0)(input)
result // $ExpectType number[]
resultCurry // $ExpectType number[]
// @ts-expect-error
pluck('b')(input)
})
})

describe('R.pluck - with list index', () => {
const input = [
[1, 2],
[3, 4],
]
it('inside piped', () => {
const result = piped(
input,
pluck(0)
)
result // $ExpectType number[]
})
it('without currying', () => {
const resultA = pluck(0, input)
resultA // $ExpectType number[]

// @ts-expect-error
pluck(1)(input)
})
})
8 changes: 1 addition & 7 deletions source/propEq-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,16 @@ describe('R.propEq', () => {

const myObject: MyType = {}
const valueToFind = '1111'
// @ts-expect-error
propEq(valueToFind, 'optional', myObject)
})

it('imported from @types/ramda', () => {
interface A {
foo: string | null,
}
const obj: A = {
const obj = {
foo: 'bar',
}
const value = ''
const result = propEq(value, 'foo')(obj)
result // $ExpectType boolean

// @ts-expect-error
propEq(value, 'bar')(obj)
})
})
17 changes: 1 addition & 16 deletions source/reduce-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {reduce, reduceStopper} from 'rambda'
import {reduce} from 'rambda'

describe('R.reduce', () => {
it('happy', () => {
Expand Down Expand Up @@ -59,21 +59,6 @@ describe('R.reduce', () => {
result // $ExpectType number
})

it('using `reduceStopper` to stop the loop', () => {
const result = reduce<number, number>(
(acc, elem, i) => {
acc // $ExpectType number
elem // $ExpectType number
i // $ExpectType number
return acc + elem > 1 ? reduceStopper(elem) : acc
},
1,
[1, 2, 3]
)

result // $ExpectType number
})

it('fallback', () => {
const result = reduce(
(acc, val) => {
Expand Down

0 comments on commit 1157bfb

Please sign in to comment.