Skip to content

Commit 674a2ac

Browse files
authored
Update constructors to receive all generics (#61)
feat: Update constructors to receive all generics BREAKING CHANGE: generic parameters changed for `success` and `failure` constructors
1 parent 867389d commit 674a2ac

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/__tests__/remote-data.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,4 +919,12 @@ describe('RemoteData', () => {
919919
});
920920
});
921921
});
922+
923+
it('types are inferred correctly when chaining', () => {
924+
const fa: RemoteData<string, number> = RD.success(1);
925+
pipe(
926+
fa,
927+
RD.chain(a => success(a)),
928+
);
929+
});
922930
});

src/remote-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ export type RemoteSuccess<A> = {
6868
export type RemoteData<E, A> = RemoteInitial | RemotePending | RemoteFailure<E> | RemoteSuccess<A>;
6969

7070
//constructors
71-
export const failure = <E>(error: E): RemoteData<E, never> => ({
71+
export const failure = <E = never, A = never>(error: E): RemoteData<E, A> => ({
7272
_tag: 'RemoteFailure',
7373
error,
7474
});
75-
export const success = <A>(value: A): RemoteData<never, A> => ({
75+
export const success = <E = never, A = never>(value: A): RemoteData<E, A> => ({
7676
_tag: 'RemoteSuccess',
7777
value,
7878
});

0 commit comments

Comments
 (0)