-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Left and Right don't unify #128
Comments
Actually I looked closer at the definition of Left.of and it doesn't do what I thought it did. In any case, replacing if with
|
This works though (in 2.4.0 not 2.3.4)
Maybe it's just ternary statements? |
Actually this works too. So maybe its just arrow functions
|
I'll close this as it seems an upstream issue |
Nevermind, I had the types backwards on the Either in the arrow functions. Whoops. |
import { Either, left, right, Left, Right } from 'fp-ts/lib/Either'
// Right.of = Left.of = right = of <= all functions are the same: return a Right You should use import { Either, left, right } from 'fp-ts/lib/Either'
// typescript v2.3.4...
const foo = (x: number) => (x < 5 ? right<string, number>(x) : left<string, number>('Not less than 5'))
const bar = (x: number) => (x > 2 ? right<string, number>(x) : left<string, number>('Not greater than 2'))
// ...or typescript v2.4.0
const foo = (x: number): Either<string, number> => (x < 5 ? right(x) : left('Not less than 5'))
const bar = (x: number): Either<string, number> => (x > 2 ? right(x) : left('Not greater than 2')) |
Yeah thanks, I realised my mistake after looking at the definition, makes sense. |
Inferred type of foo
Trying to add return type
Produces the error
This happens in both 2.3.4 and 2.4.0. But given improvements in the type checker in 2.4.0 I thought there may be a way to potentially fix. Not sure where to get started though.
Relevant changes to the typechecker in 2.4.0
microsoft/TypeScript#16072
microsoft/TypeScript#16305
microsoft/TypeScript#16368
The text was updated successfully, but these errors were encountered: