-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Unable to infer types in function passed to map
#455
Comments
I should note that |
Hi @EricCrosson. Thanks for the report. I think it's because the second argument to Lines 138 to 143 in 2f12660
TypeScript cannot infer types from overloaded functions (microsoft/TypeScript#32418 (comment)). In Fluture v11, this overload was incorrectly specified at the first function argument: Lines 271 to 277 in 00959c7
This means that TypeScript always resolves to the first overload that matches the input function (as opposed to the type of Functor), which is the version of I believe this is a case where fixing one issue introduces the other, and vice-versa. I've also had trouble with TypeScript's inference from overloaded functions when I was trying to do #438, leading me to have abandoned it for now. I would love for this problem to be solved somehow, but no luck so far. We can leave this issue open for visibility. |
Oh, and the reason my preference is to leave it at the current solution, and not go back to the v11 way (essentially dropping support for |
@EricCrosson As a work-around, you could create a Future-specialized import * as F from 'fluture'
export function map<RA, RB>(mapper: (value: RA) => RB):
<L>(source: F.FutureInstance<L, RA>) => F.FutureInstance<L, RB> {
return F.map (mapper)
}
///////////////////////////////////////////////
F.resolve(5)
.pipe(map(value => value.toString())) |
@Avaq, thank you for the quick response and suggested workaround! I appreciate the historical context you have provided. There's a lot to read and think about, so I may take some time to digest all of this. |
Following some links, I found this comment:
This makes it sound like perhaps the problematic overload can be rephrased for TypeScript to "fall back" to the " |
Another option I have been thinking about is to create more separation between the |
@EricCrosson I've started working on this, although have been unsuccessful in finding a solution. See #457. |
I also asked for help with this issue on TypeScript's Discord: https://discord.com/channels/508357248330760243/740274647899308052/796759112607203399 |
Awesome, I didn't know there was a TypeScript discord! I'll check out your post there and the PR to see if I can help |
Someone on the Discord channel found a solution. I committed it to #457. Perhaps you could install |
Sure! I'm reading through the discord conversation now -- coolest back-and-forth I've seen in a while 😎
it brought this repo to mind as it's the HKT implementation that has made the most sense to me to date, but I'm not convinced it's any simpler than his solution. I learned a ton today! Many thanks to you both 🙏 Testing
|
That traverses down the type and replaces |
Hello,
I am still using fluture 11.x in my biggest projects, and have been starting to dip my toes into v13. I may be missing something, but there seems to be an annoying bug where the function I pass to
map
cannot infer types.To reproduce:
tsconfig.json
package.json
src/index.ts
This code gives the error:
Here the type of
value
isunknown
, so thetoString()
cannot be type-checked.I find it strange that nobody has reported this, but I am able to reproduce in several of my repos, with various tsconfig settings.
The text was updated successfully, but these errors were encountered: