diff --git a/src/async.spec.ts b/src/async.spec.ts index 4844a8c..bb9004b 100644 --- a/src/async.spec.ts +++ b/src/async.spec.ts @@ -24,6 +24,10 @@ describe('Async', () => { }); it('#mapReady', () => { + expectTypeOf(Async.Pending.mapReady(() => 42)).toEqualTypeOf< + Async + >(); + const matched = Async.Pending.mapReady(() => 42).match({ Pending: () => 0, Ready: value => value, @@ -34,6 +38,12 @@ describe('Async', () => { }); it('#flatMapReady', () => { + expectTypeOf( + Async.Ready('anything').flatMapReady(s => + s === 'something' ? Async.Ready(s) : Async.Pending, + ), + ).toEqualTypeOf>(); + const matched = Async.Ready('anything') .flatMapReady(s => (s === 'something' ? Async.Ready(s) : Async.Pending)) .match({ diff --git a/src/async.ts b/src/async.ts index 242d297..96dfc30 100644 --- a/src/async.ts +++ b/src/async.ts @@ -56,7 +56,7 @@ export class Async { * values. * This is used to implement most of the operations */ - match(arms: { Pending: () => P; Ready: (value: T) => U }) { + match(arms: { Pending: () => U; Ready: (value: T) => U }) { return this.#state.isReady ? arms.Ready(this.#state.value) : arms.Pending(); } diff --git a/src/maybe.spec.ts b/src/maybe.spec.ts index f64441f..35c4abb 100644 --- a/src/maybe.spec.ts +++ b/src/maybe.spec.ts @@ -24,6 +24,8 @@ describe('Maybe', () => { }); it('#mapSome', () => { + expectTypeOf(Maybe.None.mapSome(() => 42)).toEqualTypeOf>(); + const matched = Maybe.None.mapSome(() => 42).match({ None: () => 0, Some: value => value, @@ -34,6 +36,12 @@ describe('Maybe', () => { }); it('#flatMapSome', () => { + expectTypeOf( + Maybe.None.flatMapSome(s => + s === 'something' ? Maybe.None : Maybe.Some('asdfasdf'), + ), + ).toEqualTypeOf>(); + const matched = Maybe.Some('anything') .flatMapSome(s => (s === 'something' ? Maybe.Some(s) : Maybe.None)) .match({ diff --git a/src/maybe.ts b/src/maybe.ts index 2ad1473..6a49e79 100644 --- a/src/maybe.ts +++ b/src/maybe.ts @@ -47,7 +47,7 @@ export class Maybe { * value. * This is used to implement most of the operations */ - match(arms: { None: () => N; Some: (value: T) => U }) { + match(arms: { None: () => U; Some: (value: T) => U }) { return this.#state.isSome ? arms.Some(this.#state.value) : arms.None(); }