sodiray / radash

Functional utility library - modern, simple, typed, powerful
https://radash-docs.vercel.app
MIT License
4.18k stars 167 forks source link

`chain` function can't infer data type #339

Closed fResult closed 6 months ago

fResult commented 1 year ago

From the chain function in src/curry.ts file, it has no type inferred for this function. https://github.com/rayepps/radash/blob/c3c9dac9c5da8102a8c62b1afbbb7efb9c64c31e/src/curry.ts#L5-L10

When I use the chain function, it returns any[].
Actually, I expected the return type should be Uppercase<string>[].

interface Person {
  name: string
  age: number
}

const persons: Person[] = [
  { name: 'Aa', age: 10 },
  { name: 'Ba', age: 20 },
  { name: 'Ca', age: 30 },
]

function upperCase(text: string): Uppercase<string> {
  if (!text) return ''
  return text.toUpperCase() as Uppercase<string>
}

function getName<T extends { name: string }>(item: T): string {
  return item.name
}

const upperNames = persons.map(chain(getName, upperCase))
          // ^   <--- any[]

So, I have to define the type for the upperNames variable.

const upperNames: Uppercase<string>[] = persons.map(chain(getName, upperCase))

// OR

const upperNames = persons.map<Uppercase<string>>(chain(getName, upperCase))

I want the type inferred for the chain function, that makes me annoyed a bit. 🥹
Anyone can make it able to infer?

rawnly commented 1 year ago

same here, even with the basic example seem that neither chain or compose can infer any type

const gen = () => 0;
const addOne = (x: number) => x + 1;

const g = chain(gen, addOne);

CleanShot 2023-09-03 at 19 57 13

fResult commented 9 months ago

same here, even with the basic example seem that neither chain or compose can infer any type

const gen = () => 0;
const addOne = (x: number) => x + 1;

const g = chain(gen, addOne);

CleanShot 2023-09-03 at 19 57 13

I already fixed this.
You can check this pull request.
https://github.com/rayepps/radash/pull/370

fResult commented 9 months ago

I have a question...
How can I finish this package.json? image

fResult commented 6 months ago

@rayepps This issue relates to PR#370.\ Please don't forget to close the issue. 😄