marpple / FxTS

A functional programming library for TypeScript/JavaScript
https://fxts.dev
Apache License 2.0
862 stars 63 forks source link

How to get string type on pipe? #264

Closed freevuehub closed 3 months ago

freevuehub commented 3 months ago

Bug Report

💻 Code

const text = pipe(
    ['Hello', 'World'],
    toArray, // I added the code just in case...
    join(' ')
) // Promise<string>

const text = pipe<string[], string>(
    ['Hello', 'World'],
    join(' ')
) // Promise<string>

const text = join(' ', ['Hello', 'World']) // string

🙁 Actual behavior

I tried to run a pipe and get a string type. However, I encountered an error saying that the type should be specified as Promise<string>. Although it actually runs as a string without any problem, there's an error in the code.

number type is same..

const number = pipe(
    [1, 2, 3],
    sum
) // Promise<number>

const number = sum([1, 2, 3]) // number

🙂 Expected behavior

I want the result of the last function executed in the pipe to be specified as the final type.

like this...

const text = pipe(
    ['Hello', 'World'],
    toArray,
    join(' ')
) // string

const text = pipe<string[], string>(
    ['Hello', 'World'],
    join(' ')
) // string

const text = join(' ', ['Hello', 'World']) // string

Version Information

ppeeou commented 3 months ago

@freevuehub could you let me know tsconfig?

To get the correct inferred type from fxts, you need to use the two settings below. strictFunctionTypes, strictNullChecks

https://fxts.dev/docs/getting-started#typescript

We recommend strict true to ensure correct inference.

freevuehub commented 3 months ago

@freevuehub could you let me know tsconfig?

To get the correct inferred type from fxts, you need to use the two settings below. strictFunctionTypes, strictNullChecks

https://fxts.dev/docs/getting-started#typescript

We recommend strict true to ensure correct inference.

Oh... I just checked again, and it turns out I was configuring that part in a different repo. After resetting and running it, it works well!

I will close this issue :)