Open cyrildever opened 2 years ago
It doesn't actually happen with typescript 4.7.4
only with 4.8.x
.
You're totally right. It only happens with 4.8.x
.
I didn't clean up my package-lock.json
when testing with 4.7.4
.
@Tyilo I changed it in my initial comment so that it doesn't mislead others.
Yes, monet.js
is currently incompatible with TypeScript 4.8, at least in strict mode. You can find some background on the change in TypeScript 4.8 in the announcement blogpost.
Unfortunately, the fix is not as easy as just adding extends {}
to every generic, so someone with a better understanding of the library/types will need to look into this.
Unfortunately, the fix is not as easy as just adding
extends {}
to every generic, so someone with a better understanding of the library/types will need to look into this.
Indeed. I tried a few things after cloning the repo and they all go down to the problem that, in the Maybe<T>
interface, T
extends NonNullable
. Therefore, I agree with you that it needs someone with a deep understanding of the types to work it out.
FYI: There is a quick and dirty fix but it's at the cost of removing this dependency on the NonNullable
type:
(at line 125 of src/monet.d.ts
file)
-export interface Maybe<T extends NonNullable<{}>>
- extends Setoid<Maybe<T>>, ITraversable<T>, Catamorphism<undefined, T>, Iterable<T> {
+export interface Maybe<T>
+ extends Setoid<Maybe<T>>, ITraversable<T>, Catamorphism<NonNullable<T>, T>, Iterable<T> {
/* Inherited from Monad: */
- bind<V extends NonNullable<{}>>(fn: (val: T) => Maybe<V>): Maybe<V>;
- flatMap<V extends NonNullable<{}>>(fn: (val: T) => Maybe<V>): Maybe<V>;
- chain<V extends NonNullable<{}>>(fn: (val: T) => Maybe<V>): Maybe<V>;
- map<V extends NonNullable<{}>>(fn: (val: T) => V): Maybe<V>;
+ bind<V>(fn: (val: T) => Maybe<V>): Maybe<V>;
+ flatMap<V>(fn: (val: T) => Maybe<V>): Maybe<V>;
+ chain<V>(fn: (val: T) => Maybe<V>): Maybe<V>;
+ map<V>(fn: (val: T) => V): Maybe<V>;
join<V>(): T extends Maybe<V> ? V : never;
takeLeft(m: Maybe<T>): Maybe<T>;
takeRight(m: Maybe<T>): Maybe<T>;
/* Inherited from Applicative */
- ap<V extends NonNullable<{}>>(maybeFn: Maybe<(val: T) => V>): Maybe<V>;
- apTo<V extends NonNullable<{}>> (value: Maybe<V>): T extends (arg: V) => any ? Maybe<ReturnType<T>> : never;
+ ap<V>(maybeFn: Maybe<(val: T) => V>): Maybe<V>;
+ apTo<V>(value: Maybe<V>): T extends (arg: V) => any ? Maybe<ReturnType<T>> : never;
This incompatibility is preventing us from upgrading TypeScript. Can a maintainer review the proposed Pull Request #255 to see if this is a viable fix? Alternatively, does anyone have any suggestions for alternatives to the monet package, specifically a replacement for Either?
This incompatibility is preventing us from upgrading TypeScript. Can a maintainer review the proposed Pull Request #255 to see if this is a viable fix? Alternatively, does anyone have any suggestions for alternatives to the monet package, specifically a replacement for Either?
For this reason, I had to re-write it and put it in my own utility library: ts-utls Feel free to use it.
$ npm i ts-utls
import { Either } from 'ts-utls'
const eitherString = Either('string', true)
console.assert(eitherString.isRight())
console.assert(eitherString.right() === 'string')
const rightString = Right('right')
console.assert(rightString.equals(eitherString))
When upgrading TypeScript to version
4.8.x
, I have the following compilation errors: