Skip to content

chain function can't infer data type #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fResult opened this issue Aug 24, 2023 · 4 comments
Closed

chain function can't infer data type #339

fResult opened this issue Aug 24, 2023 · 4 comments

Comments

@fResult
Copy link
Contributor

fResult commented Aug 24, 2023

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
Copy link

rawnly commented Sep 3, 2023

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
Copy link
Contributor Author

fResult commented Dec 5, 2023

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.
#370

@fResult
Copy link
Contributor Author

fResult commented Dec 5, 2023

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

@fResult
Copy link
Contributor Author

fResult commented Feb 22, 2024

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

@fResult fResult closed this as completed Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants