-
-
Notifications
You must be signed in to change notification settings - Fork 511
Closed
Description
import {Either, Left, Right} from 'fp-ts/lib/either'
const foo = (x: number) => x < 5 ? Right.of(x) : Left.of("Not less than 5")
const bar = (x: number) => x > 2 ? Right.of(x) : Left.of("Not greater than 2")
Inferred type of foo
const foo: (x: number) => Left<{}, number> | Right<{}, number> | Left<{}, string> | Right<{}, string>
Trying to add return type
const foo = (x: number): Either<string, number> => x < 5 ? Right.of(x) : Left.of("Not less than 5")
Produces the error
[ts]
Type 'Left<string, number> | Right<string, number> | Left<string, string> | Right<string, string>' is not assignable to type 'Either<string, number>'.
Type 'Left<string, string>' is not assignable to type 'Either<string, number>'.
Type 'Left<string, string>' is not assignable to type 'Left<string, number>'.
Type 'string' is not assignable to type 'number'.
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
Metadata
Metadata
Assignees
Labels
No labels